How to add a checkbox select column to jqgrid

733 views Asked by At

OK, so in my application the colModel is already prepared and I'm adding multiselect: true using setGridParam as below.

jQuery(document).ajaxComplete(function () {
  var grid = jQuery('#grid');
  grid.jqGrid('setGridParam', {
    multiselect: true
  }
});

This seems to work only partially and highlights the rows when selected. However, I'm not getting the first multiselect checkbox column. Is there an additional setting required for it.

I referred to the below examples in which the checkbox column is rendered.

http://www.guriddo.net/demo/guriddojs/selection/checkbox/index.html

http://www.trirand.com/blog/jqgrid/jqgrid.html

1

There are 1 answers

0
Tony Tomov On

The multiselect option can't be set dynamically. You can easy determine which parameter in jqGrid can be changed dynamically if you look at the last column in the options table - Can be Changed?. See the docs here.

To make this work I recommend you to do some trick.

At grid creation use multi select true to enable multiselection. Immediate after creation the grid hide the multiselect column.

When you need to enable the multiselection dynamically just show the column. The name of multi select column is combination of cb_ plus the id of the grid. The code can look like this:

// create grid
$("#grid_id").jqGrid({
...
multiselect: true,
...
});
// hide multiselect column    
$("#grid_id").jqGrid("hideCol", "cb_grid_id");
....

jQuery(document).ajaxComplete(function () {
  var grid = jQuery('#grid_id');
  // show (enable) multiselect dynamically
  grid.jqGrid("showCol", "cb_grid_id");
});