使用tablesorter jQuery对整个数据进行排序
我正在使用tablesorter对我的表进行排序.但是它似乎只对表中的可见数据进行排序.假设我有100条记录,编号为1到100,并且一次只显示10条记录,那么当我对特定的列进行排序时,只有这10条记录按升序(1-> 10)或降序(10-> 1)排序.但是我需要对整个数据进行排序(即在表中我应该得到1-> 10或100-> 91).那怎么可能?
I am using tablesorter for sorting my tables. But it seems to sort only the visible data in my table. Suppose I have 100 records numbered 1 to 100 and I display only 10 records at a time, then when I sort a particular column, only those 10 records are sorted ascendingly(1->10) or descendingly(10->1). But I need the entire data to be sorted(i.e in the table I should get 1->10 or 100->91). How is that possible?
这是我用于排序的代码:
This is the code I use for sorting:
$(".tableSort").tablesorter({
cssAsc:'asc',
cssDesc:'desc',
sortList:[[0,0]],
widgets:['zebra']
});
我现在注意到,当我移至下一页(即第二页)时,我得到的数字为90-81(整个数据已按降序排序).当我回到第一页时,我得到的数字是100-91.但是最初它显示为10-1.是什么原因?我该如何解决?
I had noticed now that when I move to the next page, i.e, the second page, there I get the numbers as 90-81 (the entire data has been sorted in descending order). And When I move back to the first page, I get the numbers as 100-91. But Initially it is displayed as 10-1. What is the reason? How do I resolve this?
您需要做的是创建标签,而不要像显示标签一样
What you need to do is create a tag and not display it like
var table = $('<table></table>');
将所有数据添加到该标签,然后执行
the add all the data to that tag and then do
table.tablesorter({
cssAsc:'asc',
cssDesc:'desc',
sortList:[[0,0]],
widgets:['zebra']
});
之所以对显示的内容进行排序,是因为您选择了要显示的表.
The reason it is sorting what is displayed, is because your selecting the table that is displayed.