Using AG Grid, i need to make a table with row selection on click, but where clicking on certain cells will NOT cause the row to be selected.
The best idea I've had so far is to disable on-click row selection when the mouse hovers over the non-selecting cell. Something like:
gridOptions.onCellMouseOver = (event) => {
if (/*cell is from non-select column*/ )
this.gridOptions.suppressRowClickSelection = true;
}
gridOptions.onCellMouseOut = (event) => {
if (/*cell is from non-select column*/ )
this.gridOptions.suppressRowClickSelection = false;
}
The only issue with this is that onCellMouseOver and Out do not seem to trigger in a timely fashion; If you quickly move from selecting a row, to clicking inside the no-select cell, the row selection will still trigger. I have an additional onCellClicked function which fires and shows that gridOptions.suppressRowClickSelection is set to true as expected, but seems like the property is not set in time when the clicks come in too fast.
If anyone knows a way around this onMouseOver timing issue, I'd love to know. Or, if there is a better way overall to implement this functionality, I'm all ear.
Thanks
suppressRowDeselection : Set to true to prevent rows from being deselected if you hold down Ctrl and click the row (i.e. once a row is selected, it remains selected until another row is selected in its place). By default the grid allows deselection of rows.
suppressCellSelection = true we can disable cell selection for all columns' cells. Here the question is regarding not showing a specific column's cell's highlighted border when it is selected. You can achieve this by bit of CSS and cellClass property of ColDef .
Range selection allows Excel-like range selection of cells. Range selections are useful for visually highlighting data, copying data to the Clipboard, or for doing aggregations using the Status Bar.
To get the currently selected rows you can then use the grid API method getSelectedRows() to return a list of all the currently selected row data.
Here's one way of doing it:
this.gridOptions = {
suppressRowClickSelection: true,
onCellClicked: (e) => {
if (e.column.colId !== 'name') { // cell is from non-select column
e.node.setSelected(true);
}
}
};
Basically, we manually select the row only when clicking cells that match the criteria.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With