Reputation: 553
I have a column with checkboxSelection=true
Under some conditions and via the API, I would like to decide whether the checkbox is readonly, i.e., I can't check/uncheck.
Is this possible?
Upvotes: 7
Views: 27156
Reputation: 73
For those still looking for an answer:
isRowSelectable
in gridConfigshowDisabledCheckboxes: true
in column defsUpvotes: 3
Reputation: 11
isRowSelectable does not work in single selection mode. Better to disable it using css
cellClassRules: { 'checkbox-disabled': isCheckboxDisabled , }
Upvotes: 1
Reputation: 761
As per documentation, you can you isRowSelectable in your gridConfig
isRowSelectable: function(rowNode) {
return rowNode.data ? rowNode.data.condition: false;
},
Upvotes: 2
Reputation: 361
If someone is still looking for an answer for this, I found a simple solution,
in your gridOptions
add the following
gridOptions = {
columnDefs: [
{
checkboxSelection: true,
cellStyle: params =>
params.value === 'YOUR_VALUE' ?
{'pointer-events': 'none'}
: ''
}
]
};
Upvotes: 8
Reputation: 695
Instead of using checkboxSelection=true, you can try cellRenderer
field: 'isMandatory',
cellRenderer: (params) => {
if (params.value) {
return `<input type="checkbox" checked/>`;
}
else {
return `<input type="checkbox" />`;
}
}
Upvotes: 2
Reputation: 2566
The property checkboxSelection can either be a boolean OR a function.
https://www.ag-grid.com/javascript-grid-column-properties/#gsc.tab=0
By using a function you can show or hide the checkbox row-based:
checkboxSelection = function(params) {
// add your cancheck-logic here
if (params.data.yourProperty) {
return true;
}
return false;
}
Disabling a checkbox is not possible out of the box. One possible way is to reset the checkbox back to it's original state:
onRowSelected:(params) => {
if(params.data.yourProperty && params.node.isSelected())
params.node.setSelected(false);
}
Upvotes: 2