Kri*_*ris 5 angular-material2 angular5 angular-cdk
我对Angular Material 中MatSort.sortChange的使用有疑问。
组态
语境
我有一个包含垫子桌子和一些按钮的组件。当用户单击某些按钮时,表格应重置为初始状态。特别是,我想将排序顺序重置为“ asc”。
有问题的
题
在此先感谢您的帮助!:)
我的守则的相关部分
export class RoleMembersComponent implements OnInit, OnChanges {
@ViewChild('inputfilter') inputfilter: ElementRef;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
ngOnInit() {
// bug#5593 START: Added this.changeDetector.detectChanges();
this.changeDetector.detectChanges();
// bug#5593 END
this.dataSource = new RoleMemberDatasource(this.database, this.paginator, this.sort);
this.onUserInteractionsWithTable();
}
private onUserInteractionsWithTable () {
const tableUserActionsListener = [
this._inputFilterChange,
this.paginator.page,
this.sort.sortChange
];
mergeOfObservables.subscribe((data : any) => {
// If internal sort do not load data again
// because reset of _inputFilterChange already trigger reload.
if (!this.isResetSort(data)) {
this.loadData();
} else {
this.sort.direction = data.direction;
}
});
}
private resetSort () {
// TODO: The content of sort seems to be ignored.
const sort = <Sort>{
active: this.defaultSortActiveFld, // works even if I put 'dummy'
direction: this.defaultSortDirection,
resetSort: true
};
this.sort.sortChange.emit(sort);
}
private isResetSort(obj: any): boolean {
return (obj.resetSort);
}
Run Code Online (Sandbox Code Playgroud)
我发现修改数据源排序active
然后direction
强制更新是有效的。
this.dataSource.sort.active = 'columnName';
this.dataSource.sort.direction = null; // reset or 'asc' / 'desc'
this.dataSource._updateChangeSubscription(); // force update table
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1644 次 |
最近记录: |