【问题标题】:jQuery tablesorter starts on wrong pagejQuery tablesorter 在错误的页面上启动
【发布时间】:2017-06-12 20:06:39
【问题描述】:

我正在使用 tablesorter (http://tablesorter.com/docs/) 和它的 AJAX 寻呼机功能。这是我用来初始化插件的代码:

$(".track-grid table.tablesorter")
    .tablesorter({
        widthFixed: false,
        cssChildRow: 'infoRow',
        widgets: ['zebra']
    })
    .tablesorterPager({
        container: $(".pager"),
        ajaxUrl : 'analyse/getEvents?page={page}&size=10&totalCount='+totalCount,

        customAjaxUrl: function(table, url) {
            // get current selection & add it to the url
            return url += '&filter=' + JSON.stringify(filter);
        },
        ajaxProcessing: function(data){
            $('#tablesorter tbody').html(data.result.eventsHtml);
            return [ parseInt(data.result.totalEventsCount) ];
        },
        page: 0,
        processAjaxOnInit: true,
        output: '{startRow} to {endRow} ({totalRows})',
        updateArrows: true,
        fixedHeight: false,
        removeRows: 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

    });

这一切都很好。事件被初始化(从后端获取),每当我点击更改页面时,都会加载新事件。但是,该页面似乎“记住”了用户上次登录其帐户的时间。例如:如果我第一次打开页面,寻呼机从第 1 页(0)开始,但是如果我切换了几个页面然后重新启动 nodeJS 服务器,重新启动浏览器和一切,每当我重新登录到应用程序时page 仍然是我手动设置的最后一个。如何强制寻呼机始终从第一页开始? (也在页面刷新时)此外,页面大小显示为 25,尽管我在初始化时将其设置为 10。我在哪里出错了?

提前谢谢你!

【问题讨论】:

    标签: jquery node.js ajax tablesorter


    【解决方案1】:

    看来您实际上是在使用fork of tablesorter,它向寻呼机添加了ajax 功能。

    您可以找到所有pager options in this documentation section。您要做的是将savePages option 设置为false

    【讨论】:

    • 感谢@Mottie 的快速回答!这确实解决了我的问题!我无法向自己解释它是如何解决“大小”问题的。我的意思是,它不再保存我之前所在的页面是合乎逻辑的,但这对页面大小从 25 到 10 有何影响?谢谢!
    • 如果您使用selected 属性设置任何寻呼机大小选项,它将覆盖初始设置。
    猜你喜欢
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多