对行进行分组和分页计数 [英] Counting Rows for Grouping and Paging
本文介绍了对行进行分组和分页计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在尝试对页面行进行下一页和下一页时,我有以下代码
I have the following code where I am trying to pagenext and previous for table rows
$( "a.paginate" ).click( function( e ) {
e.preventDefault();
if ( $( this ).attr( "id" ) == "next" ) {
//what to write here?
// firstrecord should be between 0 and max rows
// somehow page size has to be added to the firstrecord
} else {
//what to write here?
// pagesize has to be subtracted, but unable to figure how to
}
paginate( firstRecord, pageSize );
});
有人可以帮我整理一下使代码正常工作的方法吗
Can anybody help me sort how to make the code work
推荐答案
您可以使用 slice
:
You can use slice
:
描述:将匹配元素的集合简化为指定的子集 通过一系列指标.
Description: Reduce the set of matched elements to a subset specified by a range of indices.
定义要在当前页面中显示的元素.
to define the elements to display in the current page.
代码:
var firstRecord = 0;
var pageSize = 4;
var tableRows = $("#movie tbody tr");
$("a.paginate").click(function (e) {
e.preventDefault();
var tmpRec = firstRecord;
if ($(this).attr("id") == "next") {
tmpRec += pageSize;
} else {
tmpRec -= pageSize;
}
if (tmpRec < 0 || tmpRec > tableRows.length) return
firstRecord = tmpRec;
paginate(firstRecord, pageSize);
});
var paginate = function (start, size) {
var end = start + size;
tableRows.hide();
tableRows.slice(start, end).show();
}
paginate(firstRecord, pageSize);
演示: http://jsfiddle.net/H9JBT/
对于隐藏/显示下一个/上一个按钮,您可以使用 :visible
和 is
.
For hide/show next/prev button you can check if the first/last element in visible using :visible
and is
.
代码:
var paginate = function (start, size) {
var end = start + size;
tableRows.hide();
tableRows.slice(start, end).show();
$(".paginate").show();
if (tableRows.eq(0).is(":visible")) $('#previous').hide();
if (tableRows.eq(tableRows.length-1).is(":visible")) $('#next').hide();
}
演示: http://jsfiddle.net/IrvinDominin/LPwVB/
这篇关于对行进行分组和分页计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文