我有动态表,并且使用表排序器分页器运行良好,但是当我尝试过滤某些列时,它只是将我返回到第 0 页,并且没有任何反应。在某个地方,我尝试通过单击 th 对它们进行排序,其他奇怪的事情是当我在表排序器上的输入框 Debug模式中键入时说可以。
var $table = $(".track-grid table.tablesorter");
var pagesize = $('.pagesize').val();
$table.tablesorter({
widthFixed: true,
cssChildRow: 'infoRow',
widgets: ['filter'],
debug: true,
widgetOptions: {
filter_hideFilters: true,
// filter_anyMatch replaced! Instead use the filter_external option
// Set to use a jQuery selector (or jQuery object) pointing to the
// external filter (column specific or any match)
filter_external: '.search',
// add a default type search to the first name column
//filter_defaultFilter: { 1: '~{query}' },
// include column filters
filter_ignoreCase:false
}
});
$table.on('filterInit', function () {
$table.tablesorterPager({
container: $(".pager"),
ajaxUrl: `track/getEvents?page={page}&size={size}&totalCount=` + totalCount,
customAjaxUrl: function (table, url) {
return url;
},
ajaxProcessing: function (data) {
$('.tablesorter tbody').html(data.result.eventsHtml);
$('#trackOverlay').hide();
return [parseInt(data.result.totalEventsCount)];
},
page: 0,
processAjaxOnInit: true,
output: '{startRow} - {endRow} / {filteredRows} ({totalRows})',
updateArrows: true,
fixedHeight: false,
removeRows: false,
savePages: false,
cssNext: '.next', // next page arrow
cssPrev: '.prev', // previous page arrow
cssFirst: '.first', // go to first page arrow
cssLast: '.last', // go to last page arrow
cssGoto: '.gotoPage', // page select dropdown - select dropdown that set the "page" option
cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
cssDisabled: 'disabled', // Note there is no period "." in front of this class name
cssErrorRow: 'tablesorter-errorRow' // error information row
});
});
最佳答案
ajaxUrl
选项需要包含一个过滤器值。如果您查看 documentation 中的示例,你会看到这个:
ajaxUrl: "http://mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}",
{filterList:fcol}
将过滤器添加到服务器请求中。
如果内置实现不适合您,请使用 customAjaxUrl
callback修改ajax url。
关于javascript - 表排序器排序和过滤不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47631744/