0

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

Anita
  • 49
  • 1
  • 2
  • 11
  • `I have tried a lot of things` can you update your question with any one try you did? – Murali Murugesan Jul 24 '14 at 13:32
  • ya... i have posted my recent code – Anita Jul 24 '14 at 13:34
  • hey why has the question been downvoted? its a perfectly sensible question. – Anita Jul 24 '14 at 13:37
  • But i think it will be selecting all the rows in the current page in the pagination. Example, it will select only 10 rows, if you show 10 out of 500+ rows matching the search – Murali Murugesan Jul 24 '14 at 13:37
  • The question may be down voted earlier when the code was not updated. – Murali Murugesan Jul 24 '14 at 13:38
  • ya thats wat.. I want something that will select all the rows i.e 500 as per your example. I have set loadonce =true – Anita Jul 24 '14 at 13:39
  • You can set a flag like allRowsSelected=true and send it to the server along with the search criteria, then find all the matched items in server and process further. – Murali Murugesan Jul 24 '14 at 13:40
  • If you set loadonce=true, then you may need to maintain the grid from clientArray – Murali Murugesan Jul 24 '14 at 13:41
  • Check [this](http://stackoverflow.com/questions/14662632/jqgrid-celledit-in-json-data-shows-url-not-set-alert) i have loaded all the data into client array and set the datatype local and make the grid to play with local data, look into loadcomplete function – Murali Murugesan Jul 24 '14 at 13:45
  • i dint get you. I get the total number of rows in jqgrid in the tot_rows. but i dont understand why the setselection is not getting applied to it? I dont want to select based on any criteria.. i want to select all of it regardless of any criteria. – Anita Jul 24 '14 at 13:47
  • Try to check `$('#template-list').setSelection("2", true);` selects row with id=2 – Murali Murugesan Jul 24 '14 at 13:51
  • or jQuery('#template-list').jqGrid('setSelection','2'); – Murali Murugesan Jul 24 '14 at 13:52
  • ya that is exactly what i have done with setSelection. I will try the clientArray and let you know. – Anita Jul 24 '14 at 14:03
  • @murali no the clientArray thing is not working.. Can you think of something else. I am at my wits end trying to resolve this. – Anita Jul 24 '14 at 15:09

2 Answers2

3

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
0

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!!!

Anita
  • 49
  • 1
  • 2
  • 11
  • thanks this help me alot As for me var tot_rows= grid.jqGrid('getGridParam', 'records'); var gridData = grid.jqGrid('getGridParam','data'); for(var i=0; i – Aung Aung Dec 12 '17 at 12:47