I am using jqgrid as grid with multiselect:true property. I want to remove checkbox for some rows based on some row value(disable/do not allow to check). I want to add formatter on checkbox model to remove checkbox on that column
I tried to access colModel inside beforeProcessing but i dont see the column name 'cb' autoadded by jqgrid yet. hence i cannot inject formatter inside the colmodel for 'cb'.
jqGrid({
multiselect: true,
beforeSelectRow: function() {
//called when tried to select one row.
//its not called when selectAll is called.
},
onSelectAll: function(rowids, status) {
//gets selected row ids when status is true
}
})
1) I want to manipulate selection of checkboxes based on row Value.
2) checkbox should not be (visible/selectable) if row with column isApplicable=false
jgrid version: 5.3.0
It's important that you always include the version of jqGrid, which you use (can use) in the text of your question. It's important to know the fork of jqGrid too (free jqGrid, commercial Guriddo jqGrid or an old jqGrid in version <=4.7).
Free jqGrid fork, which I develop, contains some options/callbacks which can be used to implement your requirements.
First of all you can use hasMultiselectCheckBox
callback to inform jqGrid in which rows (based on the content from isApplicable
column for example) multiselect checkbox should be created:
hasMultiselectCheckBox: : function (options) {
// options is object like below
// { rowid: rowid, iRow: irow, iCol: pos, data: item, checked: checked };
// one can use options.data to examine the data of the current row
return options.data != null && options.data.isApplicable;
}
Even if the checkbox not exist in the row one can still select the row by clicking on the row. (By the way, you can use multiselectPosition: "none"
to have no column with multiselect checkboxs at all.) Thus you should add beforeSelectRow
callback additionally, which prevent selection of the rows having isApplicable
equal to false
:
beforeSelectRow: function (rowid) {
var item = $(this).jqGrid("getLocalRow", rowid);
if (item != null && !item.isApplicable) {
return true;
}
return false;
},
alternatively, if you use one of the latest version of free jqGrid, you can use rowattr
to add "jqgskipselect"
class to rows, which should be not selectable:
rowattr: function (item) {
if (!item.isApplicable) {
return { "class": "jqgskipselect" };
}
},
free jqGrid prevent selection of rows, which have the class. In old versions you can use disabled class instead for preventing selection. It's "ui-state-disabled"
class in case of usage jQuery UI CSS or "disabled"
class in case of usage Bootstrap CSS.