selecting all the rows of all the pages of a jqgrid programmatically?

蹲街弑〆低调 提交于 2019-12-23 05:41:47

问题


I want to select all the rows of all the pages in a jqgrid programatically for a batch update utility. how do i achieve this? I have tried a lot of things but none seem to work. Can anybody 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


回答1:


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.




回答2:


The reason why i wanted to select all the rows of jqgrid is so that I can get the ids of all of them using selarrrow . But I finally figured out that since thats the only reason I had wanted to select all of them , I could do that in the following way too

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!!! Thanks to both of you for your time and help!!!



来源:https://stackoverflow.com/questions/24935133/selecting-all-the-rows-of-all-the-pages-of-a-jqgrid-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!