我试图在mat表上实现mat sort,但在尝试初始化mat sort功能时遇到了一些问题。
垫子桌:
<mat-table matSort #sort1="matSort" matSortActive="id" matSortDirection="asc" matSortDisableClear
#table
[dataSource]="dataSource">
<ng-container matColumnDef="statusName">
<mat-header-cell *matHeaderCellDef mat-sort-header="customer.statusName">Status Name</mat-header-cell>
<mat-cell *matCellDef="let customer">
{{customer.statusName}}
</mat-cell>
</ng-container>
</mat-table>
组件代码:
@ViewChild('sort1', { static: true }) sort: MatSort;
ngOnInit(): void {
const sortSubscription = this.sort.sortChange.subscribe(() => (this.paginator.pageIndex = 0));
this.subscriptions.push(sortSubscription);
this.dataSource = new InvoiceStatusDataSource(this.invoiceStatusService);
this.loadItems(true);
}
loadItems(firstLoad: boolean = false) {
const queryParams = new QueryParamsModel(
{},
this.sort.direction,
this.sort.active,
this.paginator.pageIndex,
this.paginator.pageSize
);
this.dataSource.loadItems(queryParams);
this.selection.clear();
}
正如您在顶部屏幕截图中看到的,sort属性未定义。
我需要编写一些额外的代码来初始化该属性吗?