I was wondering how to have a default filter value in tablesorter. I have a parameter being passed from one page to the next, and I want that parameter to be shown in the search box. I have tried to set the value after the page is ready by using

$(document).ready(function() {
        $("#listTable").tablesorter({ headers: {0:{ sorter: 'digit'}}, debug: false, sortList: [[0, 0]], widgets: ['zebra'] })
                    .tablesorterPager({ container: $("#pager"), positionFixed: false })
                    .tablesorterFilter({ filterContainer: $("#filter-box"),
                        filterClearContainer: $("#filter-clear-button"),
                        filterColumns: [1, 2, 3, 4],
                        filterCaseSensitive: false
                    });
        $('#filter-box').val("${showAccounts}");            
  });;

This does display the showAccounts parameter inside of the "filter-box" input, but it doesn't filter by it when the page loads. Is there any way to do this?

Thanks!

有帮助吗?

解决方案

You'll need to trigger filterEnd in your page load as well. Adding the below snippet should work.

$("#listTable").trigger("filterEnd");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top