【问题标题】:How to prevent the custom tooltip from showing if the cell is currently being edited如果当前正在编辑单元格,如何防止自定义工具提示显示
【发布时间】:2020-10-28 09:53:16
【问题描述】:

下面是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;如果没有,我将其设置为未定义。这是有效的。

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

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

【问题讨论】:

    标签: ag-grid ag-grid-angular


    【解决方案1】:

    在您的自定义工具提示实现中,检查工具提示要呈现的列 (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());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多