If I have only one datatable I can sorting all values correctly. But sometimes I have nested table. For examle user can select city on the table, after that (city has lots of location ) location showns and user can select one of location on the second table. After that (location has lots of house) user can select one of house on the third table. So, sometimes I have to show to user nested table. I want to user can sort house number or house gate colour or etc. correctly. BUt sorting does not work. I checked matColumnDef and matCellDef some word. ( matColumnDef="name" and *matCellDef="let element"> {{element.name}} ) All values shown correctly so actually table work good. Only table sorting does not work. On diffrent page (has only one table like user) sorting works good. Can anybody help me ?
OnInit:
export class ListComponent implements OnInit {
nestedZoneTableData = new MatTableDataSource<any>();
senderDevicesData = new MatTableDataSource<any>();
devicesData = new MatTableDataSource<any>();
}
AfterViewInit:
ngAfterViewInit() {
this.nestedZoneTableData.sortingDataAccessor = (
data,
sortHeaderId
): string => {
return data[sortHeaderId];
};
this.nestedZoneTableData.sort = this.zsorter;
this.senderDevicesData.sortingDataAccessor = (
data,
sortHeaderId
): string => {
return data[sortHeaderId];
};
this.senderDevicesData.sort = this.sdsorter;
this.devicesData.sortingDataAccessor = (data, sortHeaderId): string => {
return data[sortHeaderId];
};
this.devicesData.sort = this.dsorter;
}
HTML too long so I can show only small part.:
<table mat-table style="background-color: pink;" [dataSource]="senderDevicesData" matSortActive="description" matSortDirection="asc"
matSort matSortDisableClear multiTemplateDataRows #sdsorter="matSort"
class=" deneme col-md-12 mat-elevation-z8">
<ng-container matColumnDef="activeFlag">
<th mat-header-cell *matHeaderCellDef mat-sort-header="activeFlag"></th>
<td mat-cell *matCellDef="let element"></td>
</ng-container>
<ng-container matColumnDef="legacyOctogateSerialnumber">
<th mat-header-cell *matHeaderCellDef mat-sort-header="legacyOctogateSerialnumber">
{{'i18n-sender-serial_number' | translate}}
</th>
<td mat-cell *matCellDef="let element"> {{element.legacyOctogateSerialnumber}} </td>
</ng-container>
...
<table style = "background-color: yellow;" mat-table [dataSource]="devicesData" matSortActive="name" matSortDirection="asc"
matSort matSortDisableClear multiTemplateDataRows #dsorter="matSort"
class="col-md-12 mat-elevation-z8">
<ng-container matColumnDef="mChannel">
<th mat-header-cell *matHeaderCellDef mat-sort-header="mChannel">
{{'i18n-sender-m_channel' | translate}}
</th>
<td mat-cell *matCellDef="let element"> {{element.mChannel}} </td>
</ng-container>
<ng-container matColumnDef="mSlaveAddress">
<th mat-header-cell *matHeaderCellDef mat-sort-header="mSlaveAddress">
{{'i18n-sender-m_slave_address' | translate}}
</th>
<td mat-cell *matCellDef="let element"> {{element.mSlaveAddress}} </td>
</ng-container>
...