问题
I'm not sure how to update the filteredPages
value in tablesorter when using server-side filtering.
I am using version 2.13.2 and am able to create custom output
which is then accessible in p.ajaxData
so that the pager displays the correct number of items shown, etc (eg, "1 to 10 of 30 (40 total)". But I don't see how to change the page dropdown at select.gotoPage
to reflect the reduced number of filtered pages. I've tried both the pager widget as well tablesorterPager
.
For example, let's say the dropdown normally allows you to choose pages 1 through 4. Now you filter and the filtered items fit on 3 pages - how is the dropdown reduced to showing only 3 pages as options?
回答1:
The pager select dropdown recalculates how many pages exist (when rows are filters) each time the page is changed or the table content is filtered.
In this case, the filteredPages
should be information that your server provides to the plugin because when using ajax, the pager automatically defaults to server side sorting and filtering. Make sure to update the pager's ajaxUrl option to include the filter and sort parameters. For example:
$(function(){
$("table")
.tablesorter()
.tablesorterPager({
ajaxUrl: "http://mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}",
ajaxProcessing: function(ajax){
// do something with the ajax
return [ formatted_data, total_rows ];
}
});
});
});
来源:https://stackoverflow.com/questions/19760156/filteredpages-in-tablesorter-with-server-side-filtering