首页 > 解决方案 > 我在 Angular 6 中使用 ag-grid。我已经实现了自定义全选功能。但是全选不能随着过滤器的变化而正常工作

问题描述

我想在过滤器更改时重新计算正确的选定行。

//服务器端全选

selectAllRows(e) {
 const firstRow = this.gridApi.getFirstDisplayedRow();
 const lastRow = this.gridApi.getLastDisplayedRow();

if(e.checked) {
  for (let idx = firstRow; idx <= lastRow; idx++) {
    this.gridApi.getDisplayedRowAtIndex(idx).setSelected(true);
    // this.gridApi.selectIndex(idx, true);
  }
  // this.gridApi.selectionController.selectAllRowNodes(true);
} else {
  this.gridOptions.api.deselectAll();
}
}

标签: angularag-gridselectall

解决方案


用于api.selectAllFiltered()选择网格中的所有过滤行。

在此处查看文档 - https://www.ag-grid.com/javascript-grid-selection/#grid-selection-api


推荐阅读