this.gridApi.refreshInfiniteCache() is not clearing selectedRows

纵然是瞬间 提交于 2019-12-11 22:54:32

问题


I am using Infinite Row Model and when i deleted the selected row from Grid then i am calling refreshing cache so lets say i deleted the selected id = 1 but after refreshInfiniteCache(); new row comes from DB via getRows() its id = 2 and that selected row does not get un-select auto and if i am clicking on delete button again then I am getting two rows in selectedData. Why is that? from this.gridApi.getSelectedRows() and getSelectedNodes() i am getting two rows previous row id = 1 and next row which came after delete that is id = 2. I should get only one row id = 2 not id = 1 again i have deleted this row and refreshed cache. Please tell me am i missing something?

deleteRow() {
const selectedData = this.gridApi.getSelectedRows();
this.assetTypeService.deleteAssetType(selectedData[0].AssetTypeID)
  .subscribe((result) => {
    this.gridApi.refreshInfiniteCache();
  })
}

回答1:


refreshInfiniteCache() : Marks all the currently loaded blocks in the cache for reload. If you have 10 blocks in the cache, all 10 will be marked for reloading. The old data will continue to be displayed until the new data is loaded.

So you can call refreshInfiniteCache() if you will replace all grid data via setRowData(rows)

setRowData(rows) Set new rows into the grid.

or you need to update the grid data after completing a delete request.

params.api.updateRowData({remove:[...array of data-objects to remove...]});



回答2:


You can try the below code inside the deleteRow() function:

   gridApi.getSelectedNodes().forEach(node => {
      var id = node.data.id;
      var rowNode = gridApi.getRowNode(id);
      rowNode.setSelected(false);
    })


来源:https://stackoverflow.com/questions/52473404/this-gridapi-refreshinfinitecache-is-not-clearing-selectedrows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!