Search code examples
tablesorter

Updating totalRows in pager after ajaxProcessing


I am building my table using tablesorter with external ajaxProcessing call.

My pager output shows filteredRows and totalRows

.tablesorterPager({

    output: '{startRow} - {endRow} / {filteredRows} filtered ({totalRows} total)  ',
    ajaxUrl:"{% url 'stats_json' %}{page}?{filterList:filter}&{sortList:column}&pagesize={size}",

}

I am returning the table rows and number of filtered rows in ajaxProcessing:

ajaxProcessing: function(data){                 
    var rows=[];
    ....
    rows.push(row);
    return [data.filtered_rows_no,rows];
}

After filtering, my filteredRows is always the same as totalRows number but they should be different.

How should I update totalRows?


Solution

  • When returning extra values from within the ajaxProcessing function don't return an array. Instead, return an object containing the total, filtered rows and any extra values as follows (ref):

    return {
      total: data.total_rows_no,
      filteredRows: data.filtered_rows_no,
      rows: rows // array of arrays
    };
    

    For the total, I am guessing that the value is contained in data.total_rows_no as I don't think the actual total would equal the rows.length value.