====== Pager ======
If your grid has only a few rows of data, then all the records will be viewable at the same time and you won't have to worry about navigating through pages of data.
But more likely, you will be dealing with large sets of data, and you'll want to display a small number of available records at a time. For this functionality, you will need the Navigation Bar.
jQuery("#grid_id").jqGrid({
...
pager : '#gridpager',
...
});
$.jgrid = {
defaults : {
recordtext: "View {0} - {1} of {2}",
emptyrecords: "No records to view",
loadtext: "Loading...",
pgtext : "Page {0} of {1}"
},
...
}
\\
{{ :wiki:pager.png | Pager }}
\\
You can change these properties different ways depending on the needs.
1. If you want globally to change these - i.e these changes will take effect in all created grids - you can do:
jQuery.extend(jQuery.jgrid.defaults,{emptyrecords: "Nothing to display",...});
You can save this code in file and load it after the jqGrid needed files are loaded.
2. If you want to change this only for a particular grid you can do:
jQuery("#grid_id").jqGrid({
...
pager : '#gridpager',
emptyrecords: "Nothing to display",
...
});
Normally, the pager placed so it appears at the bottom of the grid. A duplicate pager can also be enabled to appear at the top of the grid.
Normally when we create the pager we divide this element on three equal parts - left, center and right part. When you try to place additional information in the pager the pager try to fit the size. In case if you plan to place a lot of elements you should accordingly set the appropriate width of the grid.
By default the paging elements are placed at a center and the record information at right position of the pager.
You can change these positions using the options //pagerpos// and //recordpos// - see below.
Currently the icons that represent the pager buttons for navigating through the records are hard coded and we use the jQuery UI theming icons for this purpose.
===== Properties =====
The properties that are connected with the pager element are listed below:
^Property^Type^ Description ^Default^Can be changed?^
|lastpage|integer|Readonly property. Determines the total number of pages returned from the request. |0|No|
|pager|mixed|Defines that we want to use a pager bar to navigate through the records. This must be a valid html element; in our example we gave the div the id of "pager", but any name is acceptable. Note that the Navigation layer (the "pager" div) can be positioned anywhere you want, determined by your html; in our example we specified that the pager will appear after the Table Body layer. The valid calls can be (using our example) 'pager', '#pager', jQuery('#pager'). I recommend to use the second one.|empty string. Currently only one pagebar is possible.|No|
|pagerpos|string| Determines the position of the pager in the grid. By default, when the pager element is created it's divided into 3 parts (one part for pager, one part for navigator buttons and one part for record information)|center|No|
|pgbuttons|boolean|Determines if the Pager buttons should be shown if pager is available. Also valid only if pager is set correctly. The buttons are placed in the pager bar. |true|No|
|pginput|boolean|Determines if the input box, where the user can change the number of requested page, should be available. The input box appear in the pager bar. |true|No|
|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|See lang file|Yes|
|reccount|integer|Readonly property. Determines the exact number of rows in the grid. Do not confuse this with records parameter. Although in most cases they are equal there is a case where this is not true. For example you define rowNum parameter 15, but you return from server records parameter = 20, then the records parameter will be 20, the reccount parameter will be 15, and in the grid you will have 15 records.|0|No|
|recordpos|string|Determines the position of the record information in the pager. Can be left, center, right|right|No|
|records|integer|Readonly property. Determines the number of returned records in grid from the request|none|No|
|recordtext|string|Represent information that can be shown in the pager. This option is valid only if viewrecords option is set to true. This text appear only if the total number of records is greater than zero. In order to show or hide some information the items in {} mean the following: {0} - the start position of the records depending on page number and number of requested records; {1} - the end position; {2} - total records returned from the data| see lang file|Yes|
|rowList|array[]|An array to construct a select box element in the pager in which we can change the number of the visible rows. When changed during the execution, this parameter replaces the rowNum parameter that is passed to the url. If the array is empty the element does not appear in the pager. Typical you can set this like [10,20,30]. If the rowNum parameter is set to 30 then the selected value in the select box is 30.|empty array - []|No|
|rowNum|integer|Sets how many records we want to view in the grid. This parameter is passed to the url for use by the server routine retrieving the data|20|Yes|
|viewrecords|boolean|Defines whether we want to display the number of total records from the query in the pager bar.|false|No|
All the properties that can be changed in the pager after creating the jqGrid object require reloading the grid. This is done via the trigger("reloadGrid).
Here is a example which change the number of requested rows to 10.
===== Events =====
One event of the grid relates to the Pager:
^Event^Parameters^Description^
|onPaging|pgButton|This event fires after click on [page button] and before populating the data. Also works when the user enters a new page number in the page input box (and presses [Enter]) and when the number of requested records is changed via the select box. To this event we pass only one parameter //pgButton// (string) which can be - //first,last,prev,next// in case of button click, //records// in case when a number of requested rows is changed and //user// when the user change the number of the requested page. If the string //stop// is returned from the function then the paging will be stopped.|