Search code examples
jquerynode.jsajaxtablesorter

jQuery tablesorter starts on wrong page


I am using tablesorter (http://tablesorter.com/docs/) with it`s AJAX pager functionality. here is the code I use to initialize the plugin:

$(".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

    });

This all works well. The events are initialized (fetched from the backend), and whenever I click to change the page, new events are loaded. However, the page seems to "remember" the last time the user has logged in into his account. For example: if I open the page for the first time the pager starts at page 1 (0) but if I switch a couple of pages and then restart the nodeJS server, restart the browser and everything, whenever I login back to the app the page remains the last one I have set manually. How do I force the pager to always start at the first page? (on page refresh as well) Also, page size is shown to be 25 although I set it in the initialization to be 10. Where am I going wrong with this?

Thank you in advance!


Solution

  • It appears that you are actually using the fork of tablesorter, which added the ajax functionality to the pager.

    You can find all of the pager options in this documentation section. What you want to do is set the savePages option to false.