Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AG Grid - Suppress row selection inside a particular column/cell

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

like image 892
Kel Avatar asked Sep 10 '18 20:09

Kel


People also ask

How do you deselect rows on Ag grid?

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.

How do you turn off cell selection on Ag grid?

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 .

What is range selection?

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.

How do you get a selected cell on Ag grid?

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.


1 Answers

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.

like image 69
thirtydot Avatar answered Sep 25 '22 02:09

thirtydot