对行进行分组和分页计数

编程入门 行业动态 更新时间:2024-10-28 05:25:43
本文介绍了对行进行分组和分页计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在尝试对页面行进行下一页和下一页时,我有以下代码

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

jsfiddle/99xAU/1/

有人可以帮我整理一下使代码正常工作的方法吗

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);

演示: jsfiddle/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(); }

演示: jsfiddle/IrvinDominin/LPwVB/

更多推荐

对行进行分组和分页计数

本文发布于:2023-10-26 12:53:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530198.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!