this.gridApi.refreshInfiniteCache() is not clearin

2019-08-23 09:13发布

问题:

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);
    })