在单元格编辑触发的异步方法完成之前和之后,如何更改Ag Grid中的单元格样式?

内森·克莱门特(Nathan Clement)

当用户更新网格中的值时,我正在发出数据请求。我希望启动请求时,单元格背景变为橙色。请求完成后,我希望单元格闪烁绿色,然后再返回到其默认背景色。

这是我当前onCellValueChanged方法的简化版本

onCellValueChanged(params) {
    // I thought this would change the background to orange, 
    // but strangely, it does nothing the first time, 
    // then permanently changes the background to orange if I edit the cell again.
    params.colDef.cellStyle = {backgroundColor: 'orange'};
    // This is my data request (works)
    this.queryService.getData().then(data => {
        const cellLocation = {
            rowNodes: [this.gridApi.getDisplayedRowAtIndex(params.rowIndex)],
            columns: [params.colDef['field']]
        };
        // The cells flash correctly
        this.gridApi.flashCells(cellLocation);
        // This seems to do nothing. I thought it would clear the orange background.
        params.colDef.cellStyle = undefined;
        // I thought refreshing the grid api might make cell Styles apply, but it doesn't seem to have an impact
        this.gridApi.refreshCells(cellLocation);
        }
    }).catch(err =>
    { 
        // This error check works if my data request fails
        console.warn(err);
    });
}

根据代码段注释,getData请求正在运行并且单元格正在闪烁,但是单元格的背景颜色直到第二次编辑后才改变,此后永久变为橙色。这是正确的方法吗?如果是这样,我该如何做?如果没有,有没有人有任何建议?

内森·克莱门特(Nathan Clement)

原来问题出在refreshCells功能上。我需要使用该redrawRows功能。

首先,我需要获取当前行:

const row = this.gridApi.getDisplayedRowAtIndex(params.rowIndex);

然后,我需要在更改单元格样式后刷新该行:

params.colDef.cellStyle = {backgroundColor: 'orange'};
this.gridApi.redrawRows({rowNodes: [row]});

然后,在删除样式时,我需要做同样的事情:

params.colDef.cellStyle = undefined;
this.gridApi.redrawRows({rowNodes: [row]});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何更改已在ag-Grid中编辑的单元格的样式?

在 Ag Grid 中动态更改或设置单元格类别

向ag-grid中的特定标题单元格添加样式

如何禁用ag-grid中的单元格选择?

如何在JupyterLab中更改单元格的样式/宽度?

Ag-grid :在不使用列定义中的单元格样式属性的情况下为行中的单元格着色

动态更新Ext.grid.ActionColumn中单元格的光标样式

在 AG-GRID Angular 中插入单元格断线

如何在Angular的ag-grid中的单元格中与其他单元格值建立链接?

单元格样式的用法

JavaFX 单元格样式

更改 Tabulator 中只读单元格的样式

如何更改tableview中特定单元格的编辑样式

如何设置数据表列中的单元格样式?

更改解析PFQueryTableViewController单元格的样式

AG-Grid单元格模板值更改

如何获取Extjs Grid中单元格字段的句柄

如何从Grid View内的单元格中获取值

我可以阻止人们在 ag-Grid 中编辑特定单元格吗?

Ag-Grid:如何获得集中的单元格值

如何通过cellRendererSelector使Ag Grid显示空白单元格

根据样式在Excel中复制不同范围的单元格

SpreadsheetGear C# .NET 中的单元格样式

PHPSpreadsheet从单元格中的文本读取样式

计算单元格中的div并添加样式

ag-grid:根据同一行其他单元格中的内容禁用单元格

如何从uitableview单元格中删除单元格

如何根据jQuery中的当前单元格值更改前一个表格单元格的CSS样式和链接

Angular ag-Grid:自定义单元格渲染器,可在行中的所有可编辑单元格上打开编辑模式