【发布时间】:2020-11-21 18:02:16
【问题描述】:
我正在尝试对动态垫表中的标题进行排序,但它似乎没有做任何事情。我觉得我什么都试过了。 HTML
<table fxFlex mat-table matSort [dataSource]="dataSource">
<ng-container *ngFor="let column of columns">
<ng-container [matColumnDef]="column.jsonPath">
<th mat-header-cell mat-sort-header *matHeaderCellDef>{{column.label}}</th>
<td mat-cell *matCellDef="let obj">
{{getValueByJsonPath(obj: any}}
</td>
</ng-container>
</ng-container>
</table>
TS
dataSource = new MatTableDataSource<any>([]);
...
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
但是 matSortActive 似乎强制执行某些操作,但在第二次点击时什么也不做。
<table fxFlex mat-table matSort matSortActive="name" matSortDirection="asc"[dataSource]="dataSource">
【问题讨论】: