earthlings! I am desperately trying to get sorting to work on my mat table. At first I thought that it didn't work at all, however using
<table mat-table matSort (matSortChange)="sortData($event)" [dataSource]="source" class="mat-elevation-z8">
and
sortData(event: any){
this.dataSource.sort = this.sort;
console.log(this.dataSource.sortData(this.dataSource.data, this.sort));
this.dataSource.sortingDataAccessor
}
I am able to determine that sorting works (via console log), however my table displayed stays the same
Background: I am using a json server npm package and displaying the data (from subscription) in a mat-table. I am quite positive it has something to do with the subscription of the data (it not being avilable outright). However there are no data refreshes happening (logging refreshes as well):
loadData() {
this.dataService.getAllData().subscribe((response: any) => {
this.data = response;
this.dataSource = new MatTableDataSource<IData>(this.data);
this.dataSource.sort = this.sort;
console.log('getting Data');
});
}
I'm not sure how would I go about setting up a stackblitz for such a scenario.
I have knocked down some usual suspects - MatSortModule is imported in app module, MatColumnDef"xxx" matches data column name "xxx".
Any help would be great or if there are some other code snippets i could show.

Set initially as an empty array in property declaration
Now you will never reset dataSource by
new MatTableDataSource. Only use itsdataSource.dataproperty to set it up.