First of all it's important to understand that jqGrid supports selection of rows only on the current page. The design of jqGrid was done at the time when no local paging of data was supported.
The next problem is that one can select data only after the data have been loaded in the grid. For example one can use loadCompleted
to select some rows.
Selecting of more as one row is possible only if multiselect: true
option are used. In the case jqGrid automatically adds the column with chechboxes and it adds checkbox in the column header. By checking of the chechbox one can select all rows in the curect page. The Chechbox have id
which has the prefix cb_
and follows with the id
of the grid. For example, it will be cb_template-list
if the id of the grid is template-list
. So you can use the following code
loadComplete: function () {
$("#cb_" + this.id).click();
}
or, if the id of the grid can contains some special charachters, then better
loadComplete: function () {
$("#cb_" + $.jgrid.jqID(this.id)).click();
}
As the result all rows on every page will be selected directly after displaying the page.
UPDATE: Free jqGrid supports multiPageSelection: true
option, which works in combination with multiselect: true
. It allows to hold the parameter selarrrow
over many pages. By default jqGrid reset the array selarrrow
during paging, but in case of usage multiPageSelection: true, multiselect: true
it doesn't so resetting. Moreover it preselects all rows from selarrrow
array during the building the page. Thus if one fills selarrrow
array with all rowids of the items (all rows over all pages) then the rows will be displayed selected. The user still can deselect some rows and jqGrid will not change the changes made by the user.
By the way one can fill selarrrow
array inside of beforeProcessing
callback if the data are loaded from the server.