I have different types of items in my mat-table
: Files and Folders.
They have to get sorted like in Microsofts file-explorer. Folders can`t be separated from folders and likewise with files.
All other sorting rules staying the same.
Has anyone an idea how to solve this?
Thank you in advance!
Asked
Active
Viewed 1.1k times
4

andreas.herz
- 85
- 1
- 1
- 10
-
1.net has a entire library for files and folders but NPM does too. – JWP Apr 28 '20 at 13:03
1 Answers
9
You will have to overwrite the sortData on your MatTableDataSource attached to the table. This is the function that is responsible for sorting records, e.g.
this.dataSource.sortData = (data: YourObjectType[], sort: MatSort) => {
return data.sort((a: YourObjectType, b: YourObjectType => {
//Sorting logic here
});
}
You can look at the default implementation in the material code on github: https://github.com/angular/components/blob/c2a20c4a035ef57bf598fd78bc7284c180b34c78/src/material/table/table-data-source.ts#L168

TotallyNewb
- 3,884
- 1
- 11
- 16
-
Curious, how would I use this function to sort on an ODATA expanded property? For instance, $orderby=Location/Marina – Zadok Jan 19 '22 at 11:46