table.state.clear() but keep Column ordering and pageLength
table.state.clear() but keep Column ordering and pageLength
memme
Posts: 3Questions: 1Answers: 0
Hi,
I added a filter reset button to clear the filters with table.state.clear().
Unfortunately, it also resets the column ordering and the pageLength. How can I keep both options but clear all others?
Thank you very much
Regards
Answers
You can use
order()
andpage.len()
to get the current order before clearing the state then use those to set the order and length after the clear.Kevin
@kthorngren Thanks for reply, but it seems like its not working.
My code:
$('#reset-filter').on('click', function () {
var $length= $('#blogDatatable').DataTable().page.len();
$('#blogDatatable').DataTable().state.clear();
$('#blogDatatable').DataTable().page.len($length).draw();
window.location.reload();
});
I see. That process isn't quite right, Maybe just use
columns().search()
with an empty string to clear all the column searches. Seems that is all that is needed:http://live.datatables.net/jexadexe/1/edit
Kevin
Thanks!
The solution with columns()search('') is working on chrome, but not on firefox....
how to fix that?