Search code examples
javascriptreactjsag-grid

disable checkbox selection in Ag-grid


is it possible to disable checkbox selection by preserving some selected rows rendered with some constraints? I dont want to allow users to deselect rows which were selected while rendering.

I found this.gridOptions.suppressCellSelection = true; but this just hides the checkbox whereas i need to show the checkbox in disable mode.

Thanks.


Solution

  • I resolved it by adding rowClassRules in GridOptions

                rowClassRules: {
                    'ag-row-selected' : function(params) {
                        return params.node.selected === true;
                    },
                },
    

    This will add css as below to disable checkbox click

    .ag-row-selected{
            .ag-cell .ag-cell-wrapper .ag-selection-checkbox .ag-icon-checkbox-checked {
                pointer-events: none;
            }
        }
    

    RowClass rules are applied when grid is updated/refreshed or nodes are updated. I did it by updating specific nodes

               node.setSelected(true);
               // this is to trigger rowClass for selected/non-selected rows
               // to disable checkbox selection
               node.setData(node.data);