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 should be incorporated into a future release of jqGrid.

I've cross-posted this item in the "Bugs" forum ...

26/08/2014
10:06
Avatar
vital
New Member
Members
Forum Posts: 2
Member Since:
14/07/2014
sp_UserOfflineSmall Offline

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/09/2014
13:12
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
55 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