Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Natural Sorting in Material table #12059

Closed
rohitkrishna12 opened this issue Jul 4, 2018 · 6 comments
Closed

Natural Sorting in Material table #12059

rohitkrishna12 opened this issue Jul 4, 2018 · 6 comments

Comments

@rohitkrishna12
Copy link

rohitkrishna12 commented Jul 4, 2018

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Table to sort correctly alphanumeric characters within a column.

What is the current behavior?

Incorrectly sorts the data when alphanumeric characters are involved.
image

StackBlitz Example to reproduce the issue: https://stackblitz.com/edit/angular-zuxhe4

What is the use-case or motivation for changing an existing behavior?

To display sort results correctly in the table.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 6
Material 6.3.2
OS Windows 10
Typescript 2.9.2
Browsers - All

Is there anything else we should know?

@petivagyok16
Copy link

petivagyok16 commented Jul 5, 2018

Im experiencing the same behavior. I have a table filled with identical names, but all of them have an alphanumberical suffix e.g.:

n1-highmem-4
n1-highmem-64
n1-highmem-8
n1-highmem-96

And the sort header does not sort them correctly.

screen shot 2018-07-05 at 11 02 31 am

@crisbeto
Copy link
Member

crisbeto commented Jul 5, 2018

@rohitkrishna12 I can't reproduce the issue in your example. Here's what I get when I sort by weight:

angular-zuxhe4_-stackblitz-_google_chrome_2018-07-05_21-55-25

@rohitkrishna12
Copy link
Author

rohitkrishna12 commented Jul 5, 2018

@crisbeto 2015-410 should follow with 2015-510 then 2015-4110 and same in case of 2016 the values are not sorted correctly. Please verify.
image

@bmercier-manakin
Copy link

bmercier-manakin commented Jul 10, 2018

@rohitkrishna12 Idk what you are expecting, but I guess, as your weight data are in strings, the screenshot of @crisbeto is totally correct:
'2015-410' < '2015-4110' < '2015-510':
capture d ecran 2018-07-10 a 14 20 33

If you want another sorting method, you have to implement it yourself or display another set of data (data in numbers for instance and displaying this format with a pipe)

@rohitkrishna12
Copy link
Author

@bmercier-manakin i think i got this figured out by implementing custom sort algorithm by overrding sortData method from the MatTableDataSource class.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants