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 be incorporated into a future release of jqGrid.
I've cross-posted this item in the "Discussion" forum ...
01:22
Moderators
30/10/2007
Hello,
Thank you very much for this code.
I will think If I implement this - the reason is simple.
If you known that your table does not change the number of records for
long time this approach is OK, but in real world this is not true.
Imagine the user open a grid and stay for a long time to let say
page 3 (from 10 total). It is unknown how many pages we will have after
some time. It is possible to have 5 or 15 total pages.
So I prefer to check this server side.
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:
59 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