【发布时间】:2020-05-03 13:24:47
【问题描述】:
当用户更新网格中的值时,我正在发出数据请求。当我发起请求时,我希望单元格背景变为橙色。请求完成后,我希望单元格闪烁绿色,然后恢复为默认背景色。
这是我当前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);
});
}
根据代码 sn-p cmets,getData 请求正在运行并且单元格正在闪烁,但单元格的背景颜色在第二次编辑之前不会改变,之后它会永久变为橙色。这是正确的方法吗?如果是这样,我怎样才能使这项工作?如果没有,有人有什么建议吗?
【问题讨论】:
标签: angular typescript asynchronous ag-grid ag-grid-angular