Angular material table renderRows() 不适用于 matSort
Angular material table renderRows() does not work with matSort
我正在对垫子 deletion/addition 进行排序和 deletion/addition。table。
我一直在阅读 ,无需排序即可正常阅读。
当我在 table 上使用 mat-table
和 matSort
属性时,renderRows()
停止工作。
只要我删除排序属性,它就会再次工作。
我找到了替代解决方案,但最好知道我是否做错了什么,是否有人让它起作用,是错误还是预期行为?
无效:
delete(index: number): void {
this.dataSource.data.splice(index, 1);
this.table.renderRows();
}
有效:
delete(id: number): void {
this.dataSource.data = this.dataSource.data.filter( (item: any) => item.id !== id);
}
在按项目索引拼接()之后,您应该更新数据源。
delete(id: number, index: number): void {
this.dataSource.data.splice(index, 1);
this.table.renderRows();
this.dataSource._updateChangeSubscription(); // <-- Refresh the datasource
}
Working example link Stackblitz
我正在对垫子 deletion/addition 进行排序和 deletion/addition。table。
我一直在阅读
当我在 table 上使用 mat-table
和 matSort
属性时,renderRows()
停止工作。
只要我删除排序属性,它就会再次工作。
我找到了替代解决方案,但最好知道我是否做错了什么,是否有人让它起作用,是错误还是预期行为?
无效:
delete(index: number): void {
this.dataSource.data.splice(index, 1);
this.table.renderRows();
}
有效:
delete(id: number): void {
this.dataSource.data = this.dataSource.data.filter( (item: any) => item.id !== id);
}
在按项目索引拼接()之后,您应该更新数据源。
delete(id: number, index: number): void {
this.dataSource.data.splice(index, 1);
this.table.renderRows();
this.dataSource._updateChangeSubscription(); // <-- Refresh the datasource
}
Working example link Stackblitz