How to clear all Filter/Sorts/Pagination (without reinitializing the table from scratch)
How to clear all Filter/Sorts/Pagination (without reinitializing the table from scratch)
Eugene_B
Posts: 19Questions: 8Answers: 0
is there an easy way to reset a DataTable to its original state by removing all Filters/Sorts/Pagination the user may have applied? I want to return to the "blank state."
I posted previously that I found a way to do it by doing clear/destroy and then reinitialization,
var activeRequestsTable = $('#activeRequestsTable').DataTable();
activeRequestsTable.state.clear();
activeRequestsTable.destroy();
$('#activeRequestsTable').DataTable({
"ajax": {
url: myUrl,
dataSrc: 'activeRequests',
type: 'POST',
//etc.
}
},
"columns": [ .. ]
});
But that is a performance hit because I'm refetching data for the table. I have all the table data, I just need to reset the state quickly back to blank.
This discussion has been closed.
Replies
Hi @Eugene_B ,
No, there's no, I'm afraid to say - the only guaranteed way is to
destroy()
and reinitialise, but that would refetch data as you said. You can clear searches and pagination easily withsearch()
andpage()
respectively, but the ordering is a pickle as clearing it withorder()
can leave residue of previous searches...Cheers,
Colin