Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Pager Issues (with solutions)
29/10/2008
13:18
Avatar
davidelewis
Member
Members
Forum Posts: 20
Member Since:
16/07/2008
sp_UserOfflineSmall Offline

I've discovered two minor (but annoying!) issues with the pager component:

  1. The interface allows a user to manually select a page number that is greater than the "current" last page.
  2. 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:

$("#grid").jqGrid({
  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 ...

31/10/2008
01:22
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

31/10/2008
12:09
Avatar
davidelewis
Member
Members
Forum Posts: 20
Member Since:
16/07/2008
sp_UserOfflineSmall Offline

Well ... perhaps it could be available as an option - something like:

jQuery("#grid_id").navGrid("#pager",{standard parameters}).validateParams(true);
Smile
Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information