Sort entire data with tablesorter jQuery

 ̄綄美尐妖づ 提交于 2019-12-11 07:35:57

问题


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']
 });

EDIT: 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?


回答1:


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.



来源:https://stackoverflow.com/questions/7386682/sort-entire-data-with-tablesorter-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!