本文介绍了AG网格-禁止在特定列/单元格内选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AG Grid,我需要在单击时制作一个带有行选择的表格,但是单击某些单元格不会导致选择该行。

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;
}

唯一的问题是onCellMouseOver和Out似乎不会触发及时的方式;如果您从选择行快速转到在非选择单元格内单击,行选择仍将触发。我有一个附加的onCellClicked函数,该函数会触发并显示gridOptions.suppressRowClickSelection设置为预期的true,但是似乎单击速度太快时该属性未及时设置。

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.

如果有人知道解决onMouseOver计时问题的方法,我很想知道。或者,如果总体上有更好的方法来实现此功能,我会全力以赴。

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.

谢谢

推荐答案

这是一种方法:

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.

这篇关于AG网格-禁止在特定列/单元格内选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:16