Subarnarekha
Subarnarekha

Reputation: 115

How to apply sorting in Material table with conditional checkboxes

How can I apply sorting in Material table with conditional checkboxes:

<ng-container matColumnDef="key">
    <mat-header-cell *matHeaderCellDef mat-sort-header> Key  </mat-header-cell> 
    <mat-cell *matCellDef="let element"> {{element.key}}  </mat-cell> 
</ng-container>

Upvotes: 0

Views: 1011

Answers (1)

JuNe
JuNe

Reputation: 1997

You can solve this by setting your datasource a custom sortingDataAccesor.

this.dataSource.sortingDataAccessor = (object, columnDef) => {
   switch(columnDef) {
      case 'key':
         return object.yourValue ? 1 : 0;
      default:
         break;
   }
}

Upvotes: 1

Related Questions