jQGrid with mutliselect and default selection of rows

Tags: jquery, jqgrid, javascript

I am working with jQGrid on a project at work and we using multiselect functionality in jQGrid but with multiselect you maybe whant to default select some rows.

There was no one that shows how to do it good, so i created a function that can be used for others:



 function jQGridSelectDefault(GridID, column, defaultChecked) {
 var grid = $(GridID);
 var data = grid.getDataIDs();

 for(var i = 0; i < data.length; i++){
 var x = parseInt(grid.getRowData(data[i])[column]);
 if (jQuery.inArray(x, defaultChecked) > -1) {
 grid.setSelection(data[i], false);
 }
 }
}

You calling this function like this:

jQGridSelectDefault('#multiTicketTemplate', 'ID' [ 92, 12, 58, 64 ]);

What is doing is its looping all rows in the grid, checking the column that we specify in the call to it and if the values is in the array of ints we put in the call.

This only works on integer values but can be changed to be checked on strings also.

Add a Comment