I am using the TableSorter and Pager plugin from here: http://tablesorter.com/docs/
I want the table to display results starting at some defined index- for example, if my index is 14, I want the table to display the 'page' of results 11-20, so my row is shown, rather than starting at the default page 1, showing results 1-10.
I have this working as expected, but with some fairly ugly code..
First I work out the page that needs to be displayed (C#):
int index = 24;
int pageToDisplayFirst = 1;
while (true)
{
if (index - 10 > 0)
{
pageToDisplayFirst++;
index -= 10;
}
else
{
break;
}
}
Then I set the page by this awful loop:
for(var i = 0; i < <%= pageToDisplayFirst %>; i++) {
$(".next")开发者_StackOverflow中文版.trigger("click");
}
Here is the jQuery initialisation code, nothing special:
$("table.tablesorter").tablesorter({
cssAsc: 'sortasc', cssDesc: 'sortdesc', cssHeader: 'unsorted',
sortList: [[0,0]]
}).tablesorterPager({container: $("#pager")});
So can anyone suggest a more elegant, efficient solution?
i dont know c# but you could just do this:
pageToDisplayFirst = Math.floor(index / itemsPerPage + 1)
//found this code in the plungin source
this.defaults = {
size: 10,
offset: 0,
page: 0, <<<<
totalRows: 0,
totalPages: 0,
container: null,
cssNext: '.next',
cssPrev: '.prev',
cssFirst: '.first',
cssLast: '.last',
cssPageDisplay: '.pagedisplay',
cssPageSize: '.pagesize',
seperator: "/",
positionFixed: true,
appender: this.appender
};
maybe you this will work
$("table.tablesorter").tablesorter({
cssAsc: 'sortasc', cssDesc: 'sortdesc', cssHeader: 'unsorted',
sortList: [[0,0]]
}).tablesorterPager({container: $("#pager"), page: <%= pageToDisplayFirst %>});
精彩评论