1

When I add multiselect: true to my jqgrid, I see that jqgrid adds a checkbox for each row. Each checkbox that is displayed is unchecked. Is there a way I can preset these checkboxes based on data I'm using to populate my grid? For example, if my grid has a column called selected, and a row I'm displaying has a selected value of 1, I'd like to display the checkbox for that row as being checked. When a row's selected field is 0, I'd like to keep the checkbox as unchecked. Is this possible?

Michael Sobczak
  • 1,045
  • 1
  • 24
  • 45

3 Answers3

1

The answer on your question depends on the fork of jqGrid, which you use. I develop free jqGrid fork and implemented multiPageSelection: true option. One need just fill selarrrow array (which you can do, for example, inside of beforeProcessing based on the data returned from the server). Look at the demo created for the answer. It shows that the selarrrow array contains the ids more as on the current page. On paging or during initial filling free jqGrid set the state of chechboxes based on the selarrrow array. In the way it works effective like custom formatters, rowattr or cellattr.

If you can't upgrade to free jqGrid then you can call setSelection inside of loadComplete (see the old answer). It will work slower as in case of usage multiPageSelection: true, but it will work.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
1

In loadComplete, have something like this

var i;
var rowids = $('#myTable').jqGrid('getDataIDs');
for (i = 0;i < count = rowids.length;i+=1) {
    // condition to mark it check
    $('#myTable').jqGrid('setSelection', rowids[i], false);
}

Cheers!

DMv2
  • 198
  • 1
  • 12
0

You will need to loop through the data and apply the check.

Yogesh
  • 354
  • 2
  • 15