Skip to content

[Table] Add sort function to MatTableDataSource #8121

@quanterion

Description

@quanterion

Proposal:

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.

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentneeds: discussionFurther discussion with the team is needed before proceeding

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions