如何在当前正在编辑单元格时阻止显示自定义工具提示



下面是columnDefs下的字段配置示例。我使用customEditor作为单元格编辑器。我还将customRenderer用于单元渲染器。此外,我使用customTooltip作为工具提示。

{headerName: 'Amount', field: 'amount', lockPosition: true, width: 85,
cellEditor: 'customEditor', cellRenderer: 'customRenderer',
tooltipComponent: 'customTooltip',
tooltipValueGetter: params => params.data.amount ? params.data : undefined
...}

我知道工具提示只有在单元格上有值时才会显示。因此,使用tooltipValueGetter,我检查params.data.amount是否存在。如果是,我会将该值设置为params.data;如果没有,我将其设置为undefined。这是有效的。

但是,当我编辑单元格时,工具提示仍然会显示。编辑单元格时,如何防止工具提示显示?此外,当我删除该值时,工具提示仍然显示并且不会消失。它永远在那里。

注意:我使用的是Angular 10和最新版本的ag网格。

在自定义工具提示实现中,检查工具提示要渲染的列(params.colDef.field(是否与当前正在编辑的列相同(使用我们将设置的columnCellInEdit变量进行检查(,如果是,则不要正常渲染其他任何内容。

var columnCellInEdit ={};

onCellEditingStarted: function(event) {

columnCellInEdit.columnId  = event.column.colId;
columnCellInEdit.rowNodeId = event.node.id;
console.log('cellEditingStarted');
},
// If you dont like the above approach then use below piece 
// of code in your tooltip renderer
var cellDefs = gridOptions.api.getEditingCells();
cellDefs.forEach(function(cellDef) {
// use colid and rowIndex to confirm that the cell is being edited and not to show tooltip
console.log(cellDef.rowIndex);
console.log(cellDef.column.getId());

最新更新