[英]Angular 8 Material table, MatSort not working
我正在嘗試使用 Angular 8 並在表格中顯示數據。 顯示數據,但是即使進行了所有默認更改,排序也不起作用。
添加了 MatSortModule
客戶組件
dataSource = new MatTableDataSource<ICustomer>();
@ViewChild(MatSort,{static:false}) sort: MatSort;
ngOnInit() {
this._customers.getCustomersList().subscribe(data=>{
this.results=data;
this.dataSource=this.results.value;
console.log(this.dataSource);
});
}
ngAfterViewInit() {
this.dataSource.sort = this.sort;
}
使用@ViewChild(MatSort, {static: true}) sort: MatSort;
而不是@ViewChild(MatSort, {static: false}) sort: MatSort;
更改僅設置為static: true
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.