Datatables 1.10 add.row () not working in ajax response

Using data 1.10 with a table created by dom. I am trying to add a new row of data to the ajax response, but nothing happens. The same code alone (without ajax) works fine. Yes, response.success returns "true".

// this works and adds a new row to the table

$('#test').on('click', function () { dt.row.add( [ 'td0', 'td1', 'td2', 'td3' ] ).draw(); }); 

// the same code doesn't work in ajax response ...

 $('#dtCreate').on('click', function () { $.ajax({ type: 'post', url: '/test/process/p_db_create.php' }).done(function (response) { //double check response console.log(response); if (response.success) { //add the row since this is not serverside dt.row.add( [ 'td0', 'td1', 'td2', 'td3' ] ).draw(); ...more code below... 
+6
source share
2 answers

td should be triggered by DataTable (), not dataTable (). I ran into this problem and spent a lot of time on a good watch.

+1
source

After calling add (). draw (); Re-initialize the table by calling - dt.dataTable ();

0
source

All Articles