Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding current page number in jqGrid

Tags:

jquery

jqgrid

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.

like image 421
Ron Harlev Avatar asked Aug 28 '09 22:08

Ron Harlev


3 Answers

This should do it:

$("#sp_1").text(); // total pages

$(".ui-pg-input").val(); // current page

Edit: I found a better way in the docs for the current page but I didn't see anything for the total page count. (Click Manipulating -> Get Methods)

$('#your_grid').getGridParam('page'); // current page
like image 167
Andy Gaskell Avatar answered Nov 17 '22 01:11

Andy Gaskell


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.

like image 41
user2272605 Avatar answered Nov 17 '22 01:11

user2272605


About last page in grid, the best way is to use jqGrid - docs. In this case:

jQuery("#gridID").getGridParam('pgtext');

And if you have only 1 page, the result should be

"Page {0} of {1}"

from jqGrid wiki:

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.

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);
like image 2
P R Avatar answered Nov 17 '22 03:11

P R