In my Jquery dataTable, row.add
is not working and throws an error saying the add function is undefined. The error message is:
Uncaught TypeError: Cannot read property 'add' of undefined
jsfiddle link
html
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</tfoot>
</table>
<button id="addRow">Add new row</button>
javascript
$(document).ready(function() {
var counter = 1;
var prntTable = $('#example').dataTable( {
"aoColumns" : [
{"bSearchable" : false},
{"bSearchable" : true},
{"bSearchable" : true}
],
"sPaginationType" : "full_numbers"
} );
$('#addRow').on( 'click', function () {
prntTable.row.add( [
counter +'.1',
counter +'.2',
counter +'.3'
] ).draw();
counter++;
} );
$('#addRow').click();
} );
Instead of:
var prntTable = $("#example").dataTable();
Try:
var prntTable = $("#example").DataTable();
It looks like the old datatables API dataTable()
does not support the function you are calling. Use the new API with: DataTable()
. Read here for more info: Datatable API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With