1

I have to add columns dynamically to the mat-table, now I want to add some column rows are input fields, some are select drop-down and one is the output of all the columns. And these column names are dynamically.

How to handle those conditions in Mat-Table ?

Link: https://stackblitz.com/edit/angular-pg9fie

1 Answer 1

1

You can change the displayedColumns of *matRowDef="let row; columns: displayedColumns;"> dynamically and the table will re-render.

Just add a formControl to your mat-selection-list make your displayedColumns the value of it.

<mat-selection-list [formControl]="columnFormControl">
  <mat-list-option *ngFor="let column of ruleGroupColumns" [value]="column"></mat-list-option>
</mat-selection-list>
ruleGroupColumns: string[] = [
  'MERGE',
  'FACILITY',
  'COMPANY'
];

columnFormControl = new FormControl(this.ruleGroupColumns);

get displayColumns() {
  return this.columnFormControl.value;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.