I am trying to get the mat-table sorting to work locally, and while I can get the data to show up as expected, clicking on the header row does not do the sortin
If your table is inside an *ngIf and you think it has something to do with it not sorting your table, then specifying your own sortingDataAccessor function might solve the issue as it did for me. I have my table inside couple of *ngIfs and taking it out of those *ngIfs did not make sense:
`ngAfterViewInit(): void {
this.matchesDataSource.sort = this.sort;
this.matchesDataSource.sortingDataAccessor = previewMatchSortingFn;
}`
`export function previewMatchSortingFn(item: Match, header: string): string | number {
switch (header) {
case 'home':
return item.homeTeam.name;
case 'away':
return item.awayTeam.name;
case 'date':
if (item.dateTime) {
// this will return the number representation of the date
return item.dateTime.valueOf();
}
return;
default:
break;
}
}`