【发布时间】:2018-10-17 18:00:45
【问题描述】:
我正在构建一个带有分页的表格,该表格根据一组选定的复选框处理一些操作;我有docs,到目前为止,我只选择了几个单独的所有行,一切都很好;
我试图开始工作的情况如下:如果我的paginator 上的PageSize 是“10”,我点击masterToggle 选择“所有”行,我想要那个选择当前页面上的所有行,仅此而已,这将是与当前 PageSize 一起显示的 10 行,但是,这会选择大约 300 条记录的表的整个 dataSource。
有没有办法让masterToggle 只选择基于 PageSize 显示的行?然后,如果我将 PageSize 更改为 20,则只有前 10 个会保持选中状态。
这是我的代码。
/** Whether the number of selected elements matches the total number of rows. */
isAllSelected() {
const numSelected = this.selection.selected.length;
const numRows = this.dataSource.data.length;
return numSelected === numRows;
}
/** Selects all rows if they are not all selected; otherwise clear selection. */
masterToggle() {
this.isAllSelected() ?
this.selection.clear() :
this.dataSource.data.forEach(row => this.selection.select(row));
}
【问题讨论】:
标签: angular typescript datatable angular-material