默认情况下,在嵌套垫表未按预期工作时选中所有复选框 [英] Select All checkboxes by default in nested mat table not working as expected
本文介绍了默认情况下,在嵌套垫表未按预期工作时选中所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个嵌套的带有可展开行的MAT表。只有内部表有复选框,默认情况下,所有嵌套表中的所有复选框都必须选中。这是有效的堆叠闪电战
getProjectDetails(element: any) {
console.log(element.Id);
this.tableService.getInnerData(element.Id).subscribe((res) => {
if (res.length == 0) {
element['usersdataSource'] = new MatTableDataSource();
} else {
element['usersdataSource'] = new MatTableDataSource(res);
this.userSelectionMap.set(
element.Id,
new SelectionModel<any>(true, [element['usersdataSource']])
); // provided datasource of the current inner table for default sselection
}
});
}
我在定义选择模型时提供了默认选择的数据源的值,但它没有按预期工作。我不想遍历每个表并进行选择,因为内表的数据量可能很大。实现此目标的最佳方式是什么?
推荐答案
实例化选择模型时,需要传递element['usersdataSource'].data
而不是[element['usersdataSource']]
。
getProjectDetails(element: any) {
console.log(element.Id);
this.tableService.getInnerData(element.Id).subscribe((res) => {
if (res.length == 0) {
element['usersdataSource'] = new MatTableDataSource();
} else {
element['usersdataSource'] = new MatTableDataSource(res);
this.userSelectionMap.set(
element.Id,
new SelectionModel<any>(true, element['usersdataSource'].data) // here
); // init userSelection of the current inner table
}
});
}
这篇关于默认情况下,在嵌套垫表未按预期工作时选中所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文