[Table] Add sort function to MatTableDataSource
See original GitHub issueProposal:
Currently inside MatTableDataSource (that is inside master branch, but not released yet) there is sortingDataAccessor function that allows customization of sorting behavior. I propose to enhanсe or replace it with sortFunction
What is the use-case or motivation for changing an existing behavior?
For example, I have array of files, some of them are folders. I want to display all folders first and files last.
I can try to solve it by using data accessor that return string ${data.isFolder}${data[sortHeaderId]}
. However it doesn’t work when sort direction changed from ascending do descending and the folders will be beneath the files.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Current master branch of Anular Material
Is there anything else we should know?
I think using sortFunction = (a: T, b: T, ascending: boolean)
over sortingDataAccessor is better because sortFunction gives greater flexibility, while sortingDataAccessor just saves a single line of actual comparison.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:7 (2 by maintainers)
Top GitHub Comments
@andrewseguin is there any place where we can find an example on how to override sortData to implement custom data sorting?
@rohitkrishna12 it’s a simple example: