[英]Alternate color with Angular Material mat-table with parent child rows
[英]Angular material 2 preselect mat-table rows
我正在嘗試使用角度材料表預選行。 SelectionModel
有initialSelection
參見示例。 但是沒有確切的解釋它是如何工作的。 是否可以使用這個 initialSelection 來預選一些行?
看起來, initialSelection
需要是作為dataSource
傳遞給mat-table
的數據數組的子集。 它現在正在工作。
更新了官方示例。 查看app/table-selection-example.ts
第21 - 25
subSet1 = this.dataSource.data.slice(0,2);
subSet2 = this.dataSource.data.slice(3,5);
preselectExample = this.subSet1.concat(this.subSet2);
selection = new SelectionModel<Element>(true, this.preselectExample);
因此,在與表格和大量選擇進行了長時間的斗爭之后,我做得比切片和切塊要好一些。
this.initialSelection = this.data.filter((element,e) => {
return this.savedSelection.some( (val,i) => {
if(element.key === val.key) {
this.data[e]['amount'] = val['amount'];
return true;
}
return;
});
});
this.dataSource.data = this.data;
this.selection = new SelectionModel<any>(true, this.initialSelection);
還有一個額外的可編輯值,稍后將值分配回表中選擇的值。
干杯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.