Michael Sobczak
Michael Sobczak

Reputation: 1085

jqgrid: multiselect checkbox values

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?

Upvotes: 1

Views: 5981

Answers (3)

DMv2
DMv2

Reputation: 198

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!

Upvotes: 1

Oleg
Oleg

Reputation: 221997

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.

Upvotes: 1

Yogesh
Yogesh

Reputation: 354

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

Upvotes: 0

Related Questions