jQuery 在 jqGrid 中查找当前页码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1349700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Finding current page number in jqGrid
提问by Ron Harlev
How can I find the current page number in jqGrid (using jQuery of course). Also how do I know how many pages are there in total.
如何在 jqGrid 中找到当前页码(当然使用 jQuery)。另外我怎么知道总共有多少页。
回答by Andy Gaskell
This should do it:
这应该这样做:
$("#sp_1").text(); // total pages
$(".ui-pg-input").val(); // current page
Edit:I found a better way in the docsfor the current page but I didn't see anything for the total page count. (Click Manipulating -> Get Methods)
编辑:我在当前页面的文档中找到了更好的方法,但我没有看到总页数的任何内容。(点击操作 -> 获取方法)
$('#your_grid').getGridParam('page'); // current page
回答by user2272605
this is an old question but it might help someone,
这是一个老问题,但它可能对某人有所帮助,
$("#"+gridId).getGridParam('lastpage')
will give the last page, which is the total too. Its useful to use firebug and
将给出最后一页,这也是总数。使用萤火虫和
console.log($("#"+gridId).getGridParam());
which will show all the gridParams accessible.
这将显示所有可访问的 gridParams。
回答by P R
About last page in grid, the best way is to use jqGrid - docs. In this case:
关于网格中的最后一页,最好的方法是使用 jqGrid - docs。在这种情况下:
jQuery("#gridID").getGridParam('pgtext');
And if you have only 1 page, the result should be
如果你只有 1 页,结果应该是
"Page {0} of {1}"
from jqGrid wiki:
来自jqGrid 维基:
pgtext -> string -> Show information about current page status. The first value is the current loaded page. The second value is the total number of pages.
pgtext -> string -> 显示有关当前页面状态的信息。第一个值是当前加载的页面。第二个值是总页数。
Another way is to get all records and divide to records on page:
另一种方法是获取所有记录并划分为页面上的记录:
var rowNum = jQuery("#gridID").getGridParam('rowNum');
var allRecords = jQuery("#gridID").getGridParam('records');
var totalPages = parseInt((allRecords / rowNum) + 1);