Selecting all rows of all jqgrid pages programmatically?

I want to select all rows of all pages in jqgrid programmatically for a batch update utility. how do i achieve this? I tried a lot, but nobody works. Can someone point me in the right direction. My code is as follows:

var tot_rows=$("#template-list").jqGrid('getGridParam', 'records'); for(var i=1; i<=tot_rows; i++) { $('#template-list').setSelection(tot_rows[i], true); } 

Thanks,

Anita

0
source share
2 answers

The reason I wanted to select all jqgrid rows is because I can get the identifiers of all of them using selarrrow. But I finally realized that since this is the only reason I wanted to select them all, I could do it as follows.

 var tot_rows=$("#template-list").jqGrid('getGridParam', 'records'); var mydata = $('#template-list').jqGrid('getGridParam','data'); var indexes = $('#template-list').jqGrid('getGridParam', '_index'); for(var i=1; i<=tot_rows; i++) { recId=mydata[indexes[i]].recId; //some processing 

}

And it works !!! Thank you both for your time and help !!!

0
source

First of all, it is important to understand that jqGrid only supports row selection on the current page . The jqGrid design was completed at a time when local paging was not supported.

The next problem is that you can select data only after the data has been loaded into the grid. For example, you can use loadCompleted to select some rows.

Selecting more than one row is only possible using the multiselect: true option. In the case where jqGrid automatically adds a column with chechboxes and adds a flag in the column header. By checking the chechbox, you can select all the lines on the curect page. Chechbox has an id that has the cb_ prefix and follows with the grid id . For example, it will be cb_template-list if the grid identifier is template-list . So you can use the following code

 loadComplete: function () { $("#cb_" + this.id).click(); } 

or, if the grid identifier may contain some special characters, it’s better

 loadComplete: function () { $("#cb_" + $.jgrid.jqID(this.id)).click(); } 

As a result, all lines on each page will be selected immediately after the page is displayed.

UPDATE: The free jqGrid supports the multiPageSelection: true option, which works in combination with multiselect: true . It allows you to hold the selarrrow parameter on many pages. By default, jqGrid will reset the selarrrow array during paging, but if multiPageSelection: true, multiselect: true it does not reload. In addition, it pre-selects all rows from the selarrrow array during page assembly. Thus, if one fills the selarrrow array selarrrow all the columns of the elements (all rows across all pages), then the rows will be displayed selected. The user can still deselect some rows, and jqGrid will not change the changes made by the user.

By the way, you can populate the selarrrow array inside the selarrrow callback if the data is being downloaded from the server.

+3
source

All Articles