【发布时间】:2018-02-07 07:52:03
【问题描述】:
我正在尝试在填充数据之前清除 ag-grid。由于 rowModelType 设置为“无限”,我无法使用 setRowData() 方法更改网格数据。相反,我创建了另一个设置空数据的本地数据源,然后将其用作我的网格的数据源。我使用了下面的代码:
clearGrid(){
let self = this;
let dataSource = {
getRows(params:any) {
params.successCallback([],0);
}
};
this.gridOptions.api.setDatasource(dataSource);
}
我在这个链接中找到了它: Clear data in ag-grid
但是,当我使用上面的 clear() 函数清除网格时,看起来我无法填充任何数据,或者至少在网格中无法再看到数据。
这是我的代码,用于清除然后在我的 component.ts 中填充数据:
public populateData(formID: string) {
//Clear the grid first:
this.clearGrid();
// Create columns
this.createColumnDefs();
// Get rows from database and display them in grid:
this.gridOptions.datasource = this.dataSource;
// Refresh the grid:
this.gridOptions.api.refreshInfiniteCache();
}
如果我从代码中删除 clearGrid() 一切正常,但网格中的数据不会被清除,因此旧数据会在那里,如果新记录的数量少于旧记录,你仍然可以在网格中看到它们。
如果有人能解释我需要在哪里使用这个 clearGrid() 过程以及如何在清理其中的数据后让 ag-grid 恢复正常行为,我将不胜感激。
非常感谢您的宝贵时间!
【问题讨论】:
-
我关闭了这个问题,因为我得到了我在更新部分中解释的解决方案。