dmikester1
dmikester1

Reputation: 1362

programmatically reset filter on jquery tablesorter

I am using the jquery tablesorter from Mottie with the filter widget. Everything is working fantastic except one thing I cannot figure out. I have the table showing up in a modal. When you type some text in the filter box, then close the modal and reopen it, the text filter is still applied. I want that filter cleared/reset once the modal is reopened. I couldn't find any code to reset the filter on the tablesorter site. I can add a button that does it, but I can't figure out the specific code that does the reset.

Upvotes: 2

Views: 809

Answers (3)

Edelmar Ziegler
Edelmar Ziegler

Reputation: 111

Force the filter fields to go empty before reloading the tablesorter. Use:

$(".tablesorter-filter").val('');
$table.tablesorter({ ...options... });

Upvotes: 0

Mottie
Mottie

Reputation: 86403

If you have to re-initialize tablesorter (because there is a new table built) when the modal opens, then you can set the filter_saveFilters option to false. The previous query won't be saved to local storage and will not get applied to the table.

If you only need to "applyWidgets" to get tablesorter to work in the modal (tablesorter is not re-initialized each time), then you'll need to clear the filters by using the setFilters method as follows:

$.tablesorter.setFilters( $('table'), [] );

Upvotes: 3

jordaniac89
jordaniac89

Reputation: 574

Can you not just re-call tablesorter when the page reopens?

$("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );

Upvotes: 0

Related Questions