【问题标题】:ag-grid: How to select the all the rows on click of header checkbox for multiple pages with server side pagination in the ag-grid tableag-grid:如何在 ag-grid 表中选择具有服务器端分页的多个页面的标题复选框的所有行
【发布时间】:2022-12-05 06:14:54
【问题描述】:
我想在启用服务器端分页的 ag-grid 表的标题复选框上单击时选择所有行的 ID。目前我只能保留活动页表行 id,但我想选择具有 ag-grid 服务器端分页的多个页面的 id。
我尝试使用 getSelectedNodes() 和 getSelectedRows() apis of rowSelected events of ag-grid 但它只给我当前页面数据而不是多页数据。
请让我知道如何使用服务器端分页从多页行选择中获取数据。
【问题讨论】:
标签:
javascript
ag-grid
ag-grid-angular
【解决方案1】:
单击标题复选框时,使用 ag-grid API 以编程方式选择每个页面上的行。只需调用网格 API 上的 selectAll 方法并将 inRange 参数设置为 true 传递给它。
const gridApi = gridOptions.api;
// Select all rows
gridApi.addEventListener('selectionChanged', (event) => {
if (event.api.getSelectedRows().length === event.api.paginationGetRowCount()) {
gridApi.selectAll({ inRange: true });
}
});