How to clear DataTable with onchange in jQuery?

You may try to clear the datatable first and then destroy it.

dataTable.fnClearTable();
dataTable.fnDraw();
dataTable.fnDestroy();

Clear and destroy methods could be called like this,

var table = $('#example').DataTable();

//clear datatable
table.clear().draw();

//destroy datatable
table.destroy();

Reference;

  • Clear API method
  • Destroy method

Note: This code will work for datatable version 1.10 and above.


It could be destroy() http://datatables.net/reference/api/destroy(). Then empty the tbody.

$('#documentsTable').dataTable().destroy();
$('#documentsTable tbody').empty();