jquerytablesorter

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.


Solution

  • 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'), [] );