Search code examples
angularangular-materialangular-material-table

Angular <mat-table>: disable sort header for specific column


I have a mat-table with the matSort attribute. As I understood, this enables the sort header for all columns. Is there any possibility to disable the sort header for a single column?

With <table mat-table>...</table>, I can specify a mat-sort-header for each column, but not with <mat-table>...</mat-table>.


Solution

  • You can use the [disable] attribute:

    <th
      mat-header-cell
      *matHeaderCellDef
      [mat-sort-header]="column.name"
      [disabled]="column.name === 'actions'" // Here
      [style.width]="column.width"
    >
      {{ column.label }}
    </th>