the "key" is the lines
<mat-header-row *matHeaderRowDef="group.value"></mat-header-row>
<mat-row *matRowDef="let row; columns: group.value;"></mat-row>
Columns should be not group value else an fixed array filter if the value is in the group value. So,
<mat-button-toggle-group [multiple]="true" #group="matButtonToggleGroup"
(change)="setColumns()">
@ViewChild('group') toggle: MatButtonToggle;
columns:any[]
setColumns(){
this.columns=['position','name','weight','symbol'].filter(x=>this.toggle.value.indexOf(x)>=0)
}
And change:
<mat-header-row *matHeaderRowDef="columns"></mat-header-row>
<mat-row *matRowDef="let row; columns: columns"></mat-row>
stackblitz
NOTE you can also use a getter like
get columns()
{
return ['position','name','weight','symbol'].filter(x=>this.toggle.value.indexOf(x)>=0)
}
And you needn't use the event (change)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…