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

放肆的年华 提交于 2019-12-11 07:58:07

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/52264888/ag-grid-suppress-row-selection-inside-a-particular-column-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!