问题描述
使用tablesorter 的分页器插件可以进行服务器端分页吗?看起来默认选项要求您一次将所有行加载到浏览器的内存中.由于我有这么多记录,这实际上是不可能的,我更愿意一次加载一页.tablesorter 寻呼机插件是否支持这个?如果是这样,我错过了什么,因为文档显示了这个例子:
Is server side pagination possible with tablesorter's pager plugin? It looks like the default options require you to load all your rows into browser's memory at once. Since I have so many records this isn't really possible, I would prefer to load one page at a time. Does the tablesorter pager plugin support this? 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 ];
}
},
那个,以及我能找到的其他例子,看起来像是在 ajax 处理函数中一次将所有行加载到内存中.
That, and other examples I've been able to find, look like it loads all rows at once into memory in the ajax processing function.
http://mottie.github.com/tablesorter/docs/example-pager.html
更新:
在 http://mottie.github 上看到 AJAX 寻呼机后.com/tablesorter/docs/example-pager-ajax.html 我还有几个问题:
After seeing the AJAX pager at http://mottie.github.com/tablesorter/docs/example-pager-ajax.html I have a few questions still:
- sortList = [[2,0],[3,0]].在 Ajax URL 中,我是否自己转换为 &col[2]=0&col[3]=0 的真实格式?
ajaxProcessing 的文档说:
- sortList = [[2,0],[3,0]]. In the Ajax URL, do I do the conversion to the real format of &col[2]=0&col[3]=0 myself?
The documentation for the ajaxProcessing says:
处理ajax,返回如下信息://[ total_rows (number), rows (array of arrays), headers (array; optional) ]
process ajax so that the following information is returned:// [ total_rows (number), rows (array of arrays), headers (array; optional) ]
看起来total_rows是数据库中的行数,而不是浏览器内存中或表中显示的行数.那是对的吗?下一个问题:我了解行"数组的格式.但是哪些行实际上应该在其中?文档说它是所有行",但它只是表中显示的行的当前页面吗?是用户迄今为止翻过的所有行吗?我认为这不是数据库中的所有行,因为这会完全破坏这一点.
It looks like total_rows is the number of rows in the database, not the number of rows in the browser memory or shown in the table. Is that correct? Next question: I understand the format of the "rows" array of arrays. But which rows are actually supposed to be in it? The documentation says it's "all rows" but is it just the current page of rows that is being displayed in the table? Is it all of the rows that the user has paged through thus far? I assume it isn't all of the rows that are in the DB because that would ruin the point entirely.
推荐答案
要包含排序列和方向,只需在 url 模板中的示例中包含服务器端变量 col
:
To include the sort column and direction just include the server side variable col
in the example within the url template:
ajaxUrl : "http:/mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}",
{page}
是用户正在查看的当前页面,{size}
是要在浏览器中显示的行数.
The {page}
is the current page the user is viewing and {size}
is the number of rows to show in the browser.
Include &{sortList:col}
(col
匹配服务器端变量的排序列和方向)以包括排序.并包含 &{filterLost:fcol}
(fcol
匹配服务器端变量以过滤列)以包含任何过滤.寻呼机插件为您将字符串格式化为 &col[2]=0&col[3]=0
(或其他).
Include &{sortList:col}
(with col
matching the server side variable for sort column and direction) to include sorting. And include &{filterLost:fcol}
(with fcol
matching the server side varibale for filtering columns) to include any filtering. The pager plugin formats the string into &col[2]=0&col[3]=0
(or whatever) for you.
如果您查看 ajaxProcessing
函数,它所做的只是将 当前行集 的服务器中的 ajax 数据重新格式化以显示(并非所有行)到匹配此所需格式:
If you look at the ajaxProcessing
function, all it does is reformat the ajax data from your server of the current set of rows to display (not all rows) to match 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
]
如果您的数据库中有不确定的行数,只需返回 0
...它应该仍然有效,但是 totalPages
和 totalRows
变量将不准确.
If you have an indeterminate number of rows in your database, just return 0
... it should still work, but then the totalPages
and totalRows
variables will be inaccurate.
这篇关于使用 tablesorter 进行服务器端分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!