Datatables JS showing records again on

Viewed 72

I'm making use of an instance of Datatables JS.

I've created 2 buttons that filter on two different values within one column as follows :

$('#published').click(function() {
    table.column(2).search('Published').draw();
}); 

$('#concept').click(function() {
    table.column(2).search('Concept').draw();
}); 

On click on these buttons, the table shows the value that meets the .search, just as expected. Now I've tried to create an "all" button, so the table shows me all records again (a kind of reset to all records). Unfortunately, I'm not getting that to work. I've tried to re-initialize the table but I'm unable to show all results again without refreshing.

Unfortunately, JS is not my strong suit.

Any help would be very much appreciated!

Thanks in advance,

2 Answers

You can clear filter of your table with

table.search( '' ).columns().search( '' ).draw(); 

or

table.search("").draw();

As per the Datatable official documentation

For jQuery DataTables 1.10

Below code will remove all filtering that has been applied to a DataTable, be it column based filtering or global filtering.

table
 .search( '' )
 .columns().search( '' )
 .draw();

For jQuery DataTables 1.9

Call fnFilter() API method with empty string as a first argument to reset the global search and redraw the table.

For example:

    table.fnFilter('');
Related