I have REST API that only supports ascending sort, is it possible to disable descending sort direction in MatTable but keep ascending direction and no sort option?
CodePudding user response:
Does this answer your question?
If you want to prevent the user from changing the sorting order of any column, you can use the
matSortDisabled
binding on themat-sort
, or thedisabled
on a singlemat-sort-header
.
CodePudding user response:
It's only override the function sort of the MatSort
@ViewChild(MatSort,{static:true}) sort: MatSort;
ngOnInit()
{
this.sort.sort=(sortable: MatSortable)=>{
if (this.sort.active != sortable.id) {
this.sort.active = sortable.id;
this.sort.direction = sortable.start ? sortable.start : this.sort.start;
} else {
this.sort.active=''
}
this.sort.sortChange.emit({active: this.sort.active, direction: this.sort.direction});
}
this.dataSource.sort=this.sort
}