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>
.
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>
you can remove mat-sort-header
from th
to prevent it from sorting
<table matSort (matSortChange)="sortData($event)">
<tr>
<th mat-sort-header="name">row-1</th> // sortable
<th>row-2</th>
<th>row-3</th>
</tr>
<tr *ngFor="let row of sortedTable">
<td>{{ row.name }}</td>
<td>{{ row.email }}</td>
<td>{{ row.address }}</td>
</tr>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With