【问题标题】:Table Sorter sorting and filtering didn't work表格排序器排序和过滤不起作用
【发布时间】:2017-12-04 10:56:04
【问题描述】:

我有动态表格,并且我使用表格排序器分页器运行良好,但是当我尝试过滤某些列时,它只是将我返回到第 0 页并且什么也没发生。在某个地方,我尝试通过单击对它们进行排序,而其他奇怪的事情是,当我在表格排序器的输入框调试模式中键入时说没问题。

       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

            });
        });

【问题讨论】:

    标签: javascript jquery tablesorter


    【解决方案1】:

    ajaxUrl 选项需要包含一个过滤器值。如果您查看documentation 中的示例,您会看到:

    ajaxUrl: "http://mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}",
    

    {filterList:fcol} 将过滤器添加到服务器请求中。

    如果内置实现对您不起作用,请使用customAjaxUrl callback 修改 ajax url。

    【讨论】:

    • 谢谢我昨天找到它并且工作正常但现在我有排序列的问题我知道如何排序但我不知道点击了哪一列。当我单击表格上的每一列时,它的反应相同,我尝试获取 html 来为 diff 列创建差异逻辑,但 customAjaxUrl: 在获得列名称之前返回 url 你能给我一些建议吗?跨度>
    • ajaxUrl 中还有一个{sortList:col},用于将列列表和排序方向传递给服务器。
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签