I'm using jQuery DataTables and adding rows after a successful insert to a DB. How can I force a refresh of the table? I have checked on docs but found only how to refresh if data is loaded with Ajax. I'm adding to the tbody client side.
1 Answer
If you are using legacy datatable
tableObj.fnClearTable();
tableObj.fnAddData(data);
tableObj.fnDraw();
also fnRedraw(), If you want to redraw the table
If you are using new Datatable then this may help you.
var table = $('#example').DataTable();
$('#myFilter').on( 'keyup', function () {
table
.search( this.value )
.draw();
} );
var table = $('#example').DataTable();
// Sort by column 1 and then re-draw
table
.order( [[ 1, 'asc' ]] )
.draw( false );
<tr>and one or more<td>s) then it should show but won't be registered with DataTables and thus won't be searchable, orderable and what have you. If you're adding it using thetable.row.add(...row data...), method then all is good, just adddraw()to the end so:table.row.add(...row data...).draw(). Hope that helps.