Where to start the subset. The first element is at zero. Can be negative to start from the end of the selection.
Where to end the subset (does not include the end element itself). If unspecified, ends at the end of the selection.
今天编写完数据分页,总结一下,完整的分页算法:
//对建立完好的表格进行分页处理
$("table.sortable").each(function(){
var currentPage = 0;
var numPerPage = 10;
var $table = $(this);
$table.bind("repaginate", function() {
$table.find('tbody tr').hide()
.slice(currentPage * numPerPage, (currentPage + 1) * numPerPage)
.show();
});//repaginate
var numRows = $('table.sortable').find("tbody tr").length;
var numPages = Math.ceil(numRows/numPerPage);
var $pager = $('<div class="page"></div>');
for(var page=0;page<numPages;page++){
$('<a href=# ><span class="page-number">' + (page + 1) + '</span></a>').bind("click", { "newPage": page }, function(event) {
currentPage = event.data["newPage"];
$table.trigger("repaginate");
$(this).addClass("active").siblings().removeClass("active");
}).appendTo($pager);
$pager.append(" ");
} //for
$pager.find("span.page-number:first").addClass("active");
$pager.insertAfter($table);
$table.trigger("repaginate");