Forum
13:18
16/07/2008
I've discovered two minor (but annoying!) issues with the pager component:
- The interface allows a user to manually select a page number that is greater than the "current" last page.
- The interface does not update the last page when the number of rows per pages is adjusted such that the last page will exceed the number of records.
Although both of these issues can be corrected with the server-side code that generates the row listing - this is not always possible (depends on how the server side implementation works). Therefore, I have added additional code to the "client" so that these issues are resolved before the request is made to the server:
onPaging: function (pgButton) {
// if user has entered page number
if ("user" == pgButton) {
// find out the requested and last page
var requestedPage = $("#grid").getGridParam("page");
var lastPage = $("#grid").getGridParam("lastpage");
// if the requested page is higher than the last page value
if (eval(requestedPage) > eval(lastPage)) {
// set the requested page to the last page value
$("#grid").setGridParam({page: lastPage});
}
// otherwise, if the number of records per page has changed
} else if ("records" == pgButton) {
// find out the requested page, totolal number of rows, and rows per page
var requestedPage = $("#grid").getGridParam("page");
var totalRows = $("#grid").getGridParam("records");
var rowsPerPage = $("#grid").getGridParam("rowNum");
// calculate what last page SHOULD be
var lastPage = Math.ceil(eval(totalRows) / eval(rowsPerPage));
// if the requested page is greater than what the last page should be
if (eval(requestedPage) > lastPage) {
// set the requested page to the last page value
$("#grid").setGridParam({page: lastPage});
}
}
...
}
}
});
I'd like to suggest that this solution should be incorporated into a future release of jqGrid.
I've cross-posted this item in the "Bugs" forum ...
10:06
14/07/2014
For those, who came here from google as i am, an updated solution for newer grid versions should look like:
onPaging: function(pgButton) { Â Â Â Â Â Â Â Â Â Â Â var newpage, last; Â Â Â Â Â Â Â Â Â Â Â if ("user" == pgButton) { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â newpage = parseInt($(this.p.pager).find('input:text').val()); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â last = parseInt($(this).getGridParam("lastpage")); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (newpage > last) { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return 'stop'; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â Â Â Â Â } Â Â Â Â Â Â Â },
13:12
Moderators
30/10/2007
Hello,
Â
Thanks for posting this solution.
Â
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
58 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66