【发布时间】:2018-08-23 08:05:38
【问题描述】:
我已经阅读了我不知道有多少示例,据我所知,我正确地遵循了示例,但是当我单击标题时列没有更新。
-我在 app.module.ts 中包含了 MatSortModule
-我在 mat-table 中包含了 matSort
-我在我希望能够排序的列的标题单元格中包含了 mat-sort-header(所有列)
-我已经包含了@ViewChild(MatSort) sort: MatSort;以及相应的
ngAfterViewInit() {
this.dataSource.sort = this.sort;
}
我看不出还剩下什么。这是我的代码 sn-p:
<mat-table #table [dataSource]="dataSource" matSort class="dataTable">
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell
*matHeaderCellDef
fxLayout="row"
fxLayoutAlign="start center"
mat-sort-header
class="clickable"
>
Product Name
</mat-header-cell>
<mat-cell
*matCellDef="let item"
class="table-cell-content"
>
{{item.name}}
</mat-cell>
</ng-container>
...
defaultData: Array<Object> = null;
dataSource = new MatTableDataSource(this.defaultData);
@ViewChild(MatSort) sort: MatSort;
constructor(private getDataService: GetDataService) {
this.getDataService.getData()
.subscribe(data => {
this.defaultData = data;
this.dataSource.data = this.defaultData;
},
err => console.log(err));
}
...
ngAfterViewInit() {
this.dataSource.sort = this.sort;
}
【问题讨论】:
-
出于好奇,这是该组件上唯一的表吗?如果同一个组件中有多个表,则必须采用一种奇怪的方法。
-
是的,它是唯一的表。什么看起来很奇怪?
标签: angular datatable angular-material