Server side pagination with tablesorter

Is pagination possible with tablesorter plugin plugins? It looks like the default options require you to immediately load all of your lines into your browserโ€™s memory. Since I have so many entries, this is not realistic, I would prefer to load one page at a time. Does the plugin plugin support tablesorter? If so, what am I missing because the documentation shows this example:

// process ajax so that the data object is returned along with the total number of rows // example: { "data" : [{ "ID": 1, "Name": "Foo", "Last": "Bar" }], "total_rows" : 100 } ajaxProcessing: function(ajax){ if (ajax && ajax.hasOwnProperty('data')) { // return [ "data", "total_rows" ]; return [ ajax.data, ajax.total_rows ]; } }, 

These and other examples that I could find are similar to the fact that it loads all the lines at once into memory in the ajax processing function.

http://mottie.github.com/tablesorter/docs/example-pager.html

Update:

After watching the AJAX pager at http://mottie.github.com/tablesorter/docs/example-pager-ajax.html I still have a few more questions:

  • sortList = [[2,0], [3,0]]. In the Ajax url, do I convert to the real format & col [2] = 0 & col [3] = 0 myself?
  • The documentation for ajaxProcessing says:

    process ajax so that the following information is returned: // [total_rows (number), strings (array of arrays), headers (array; optional)]

It seems that total_rows is the number of rows in the database, not the number of rows in browser memory or shown in the table. It's right? Next question: I understand the format of the "rows" array of arrays. But what lines should really be in it? The documentation says it's โ€œall rows,โ€ but is this just the current row page displayed in the table? Are these all the lines that the user has laid so far? I assume that this is not all the rows that are in the database, because it will completely destroy the point.

+4
source share
1 answer

To enable the sort column and direction, simply include the col server variable in the example in the URL pattern:

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

{page} is the current page the user is viewing, and {size} is the number of lines displayed in the browser.

Enable &{sortList:col} (with col server-side variable matching for column and sort direction) to enable sorting. And enable &{filterLost:fcol} (with fcol matching varibale on the server side to filter columns) to enable any filtering. The pager plugin formats the string at &col[2]=0&col[3]=0 (or something else) for you.

If you look at the ajaxProcessing function, all it does is reformat the ajax data from your server from the current rowset to display (not all rows) to fit this required format:

 // process ajax so that the following information is returned: // [ total_rows (number), rows (array of arrays), headers (array; optional) ] // example: [ 100, // total rows [ [ "row1cell1", "row1cell2", ... "row1cellN" ], [ "row2cell1", "row2cell2", ... "row2cellN" ], ... [ "rowNcell1", "rowNcell2", ... "rowNcellN" ] ], [ "header1", "header2", ... "headerN" ] // optional ] 

If you have an undetermined number of rows in your database, just return 0 ... it should still work, but then the variables totalPages and totalRows will be inaccurate.

+2
source

All Articles