sortDataColumns(data, sort) {
switch (sort.active) {
case 'Priority': {
return (this.dataSource.sortData = (data) => {
return data.sort((a, b) => {
const propertys = this.prioritySortOrder[a.Priority] - this.prioritySortOrder[b.Priority];
if (!sort.direction) return;
if (sort.direction === 'asc') {
return propertys;
} else {
-propertys;
}
});
});
}
default:
return data;
}
}```
I have something like this so far
#Custom sorting material table
1 messages · Page 1 of 1 (latest)
MatTablDataSource has a sortingDataAccessor property: https://material.angular.io/components/table/api#MatTableDataSource
I thought the use case for this was for nested object properties??
Or would it work with something like this
ngOnInit(): void {
this.dataSource.sortingDataAccessor = (item, property) => {
switch (property) {
case 'Priority':
return this.getComparablePriority(item.Priority);
default:
return item[property];
}
};
}
You can answer that question by yourself, by testing it.