【发布时间】:2018-09-21 06:58:08
【问题描述】:
您好,我有一些带有自定义渲染的单元格 当我更新所有数据时,deltaRowDataMode 不会改变我的 cutsom 单元格渲染。更新行的其他单元格已正确更新。
如何为 ag grid 提供线索以正确比较此自定义单元格
【问题讨论】:
-
请分享sn-p更多权限
标签: updates ag-grid cellrenderer
您好,我有一些带有自定义渲染的单元格 当我更新所有数据时,deltaRowDataMode 不会改变我的 cutsom 单元格渲染。更新行的其他单元格已正确更新。
如何为 ag grid 提供线索以正确比较此自定义单元格
【问题讨论】:
标签: updates ag-grid cellrenderer
我刚刚遇到了同样的问题,并从 ag-grid 文档中找到了线索。在Cell Renderer 帮助文档中,它谈到了ICellRendererComp.refresh 方法:
// Mandatory - Get the cell to refresh. Return true if the refresh succeeded, otherwise return false. // If you return false, the grid will remove the component from the DOM and create // a new component in it's place with the new values. refresh(params: ICellRendererParams): boolean;
在下面的例子中:
// gets called whenever the user gets the cell to refresh MyCellRenderer.prototype.refresh = function(params) { // set value into cell again this.eValue.innerHTML = params.valueFormatted ? params.valueFormatted : params.value; // return true to tell the grid we refreshed successfully return true; };
然后我在CellRenderer 上实现了如下刷新功能,而不更改任何单元格内容:
statusCellRenderer.prototype.refresh = function (params) {
//ensure the status cell\directive refreshes when the grid data is refreshed using deltaRowDataMode
this.params = params;
return true;
};
因此,在我的情况下,我在轮询循环中刷新网格的rowData,我不希望网格继续丢失选定的行。我在gridOptions 上设置了deltaRowDataMode 和getRowNodeId 属性,然后实现了刷新功能以使单元格在刷新时重新渲染。刷新还会在我的单元格中重新呈现指令。
【讨论】:
gridAPI.refreshCells() 并没有初始化全宽单元格渲染器,而是使用gridAPI.redrawRows() 来初始化和拆除全宽单元格渲染器。见Redraw Rows