Components: Natural Sorting in Material table

Created on 4 Jul 2018  路  6Comments  路  Source: angular/components

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?

All 6 comments

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-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

@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

@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

@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)

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

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MurhafSousli picture MurhafSousli  路  3Comments

michaelb-01 picture michaelb-01  路  3Comments

theunreal picture theunreal  路  3Comments

Miiekeee picture Miiekeee  路  3Comments

vitaly-t picture vitaly-t  路  3Comments