mat-sort无法处理mat-table来自另一个数据库的的一个列,其余的列则工作正常。唯一的区别是,我正在从另一服务获取该列的数据。
我试图解决它,ngAfterViewInit但无济于事。
ngAfterViewInit(){
this.dataSource.sort = this.sort;
};
Run Code Online (Sandbox Code Playgroud)
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Resource </th>
<td mat-cell *matCellDef="let element"> {{element.creator.name}} </td>
<td mat-footer-cell *matFooterCellDef> </td>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
displayedColumns: string[] = ['projectName', 'date', 'hours', 'description', 'name', 'location', 'Edit'];
@ViewChild(MatSort) sort: MatSort;
ngOnInit(){
this.dataSource.sort = this.sort;
}
Run Code Online (Sandbox Code Playgroud)