Clearing all search filters without triggering the event
Clearing all search filters without triggering the event
I have a datatable with ~19,000 rows. On the same page I have an "advanced search" component where I allow users to search the data using the search API, e.g.: table.column(4).search( ... );
I also use the datatables built in search:
$('#gridTable').on( 'search.dt', function (e, settings) {
// some function to show the number of rows
} );
In my advanced search, I want to clear all of the search filters and apply new ones. I do this again using the API:
table.columns().search('');
The problem is that my table has 11 columns and thus the search event gets triggered 11 times. This is slow. Is there a better way for me to clear all of the column filters? Would I be better off reloading the whole table?
Replies
maybe you could do it like this? I guess this would clear everything first, and only then redraw.
Apparently my first post is awaiting moderator approval... for now I solved the problem by clearing the table data, removing all the filters, executing my business logic, adding the rows back to the table, and then redrawing.
I solved half my problem by turning the event on and off (very cool!).
table.off( 'search.dt' );
.. Do stuff
table.on( 'search.dt' );
BUT, removing all of the filters still takes too long:
console.log(">> Clearing filters");
table.columns().search('');
console.log("<< Clearing filters");
... do stuff
table.draw();
My console log shows that clearing the filters takes five seconds.
Any suggestions on how I can remove all of the filters more efficiently?
Oops - sorry. post approved now :-)