Skip to main content


Showing posts with the label Dynamic-Columns-Mat-Table

Angular Material Table Dynamic Columns|Dynamic-columns-mat-table


Here we have solution for dynamic Mat table columns

Step 1: Create column Definition Model class

export  class ColumnDefinition {
    columnDef: string;
    header: string;
    cell: any;
    constructor(_columnDef: string, _header: string, _cell: any) {
     this.columnDef = _columnDef;       this.header = _header; this.cell = _cell;
  }Step 2: Add Mat-Table Defintion as below in Html Template 
<table mat-table [dataSource]="mattabledataSource" matSort class="mat-elevation-z8">
    <ng-container *ngFor="let col of displaycolumndefs" matColumnDef="{{col.columnDef}}" >
        <div   >
            <th mat-header-cell *matHeaderCellDef  mat-sort-header > {{col.header}}  </th>
            <td mat-cell *matCellDef="let element">{{ col.cell(element) }}</td>
      <tr mat-header-row *matHeaderRowDef="displayedColum…