Reputation: 3263
I have a table, which gets dataform Javascript array. After the array gets changed, I want to change the data shown in the table without recreating it again. I start the table with
$('#table').dataTable( {
"bPaginate": false,
"data": dataArray,
"columns": [
{ "title": "....
Later on I will add one more record to dataArray, but want to preserve all the sorting, filters,... How do I redraw table with new contents of the dataArray?
Upvotes: 0
Views: 4856
Reputation: 1889
If you are looking to add a new Row to your table you can take advantage of the add row API
var table = $("#table").DataTable();
t.row.add( [
"col 1 value" ,
"col 2 value",
...
"col 5 value"
] ).draw();
http://www.datatables.net/examples/api/add_row.html
Upvotes: 1
Reputation: 13243
You need to put all this code in your fnInitComplete
function.
Like this:
$(document).ready( function() {
$('#example').dataTable( {
"fnInitComplete": function(oSettings, json) {
alert( 'DataTables has finished its initialisation.' );
if(...){
//load the new array
oSettings.aoData = newArray;
//redraw the table
$(this).fnDraw();
}
}
} );
} )
Upvotes: 1