Typescript AG Grid-抑制特定列/单元格内的行选择
使用AG Grid,我需要在单击时创建一个表,其中包含行选择,但单击某些单元格不会导致选中行 到目前为止,我的最佳想法是,当鼠标悬停在非选择单元格上时,禁用单击行选择。比如:Typescript AG Grid-抑制特定列/单元格内的行选择,typescript,ag-grid,Typescript,Ag Grid,使用AG Grid,我需要在单击时创建一个表,其中包含行选择,但单击某些单元格不会导致选中行 到目前为止,我的最佳想法是,当鼠标悬停在非选择单元格上时,禁用单击行选择。比如: gridOptions.onCellMouseOver = (event) => { if (/*cell is from non-select column*/ ) this.gridOptions.suppressRowClickSelection = true; } gridOptions.onCel
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,但当单击速度过快时,该属性似乎没有及时设置
如果有人知道如何解决这个时间问题,我很想知道。或者,如果总的来说有更好的方法来实现这个功能,我完全同意
谢谢这里有一种方法:
this.gridOptions = {
suppressRowClickSelection: true,
onCellClicked: (e) => {
if (e.column.colId !== 'name') { // cell is from non-select column
e.node.setSelected(true);
}
}
};
基本上,我们只在单击符合条件的单元格时手动选择行。我使用此解决方法是因为我需要在单击时选择全宽行,但在单击第一列后,我应该导航
<ag-grid-angular (gridReady)="onGridReady($event)" (rowClicked)="onRowClick($event)">
onRowClick(params: RowClickedEvent) {
if(this.gridApi.getFocusedCell().column.getColId() === 'number'){
this.goToItem(params.data.id);
return;
}
//Other row logic
}
嗯,是的,应该有用。当然,这将需要对我的项目当前使用的设置进行相当多的重构。我对其他想法持开放态度,但我现在就接受这个观点。可能还有其他方法,但这些方法也很难在您的项目中实施。如果您无法让它工作,也许可以围绕当前使用的
onCellClicked
,提出一个新问题,并提供更多上下文。我只能回答我能看到的限制。
gridApi: GridApi;
gridColumnApi: ColumnApi;
onGridReady(params: any) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
}