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

bug(table-data-source): Sorting of a string column/property breaks if one record contains a number only #20140

Open
stnor opened this issue Jul 30, 2020 · 3 comments

Comments

@stnor
Copy link

@stnor stnor commented Jul 30, 2020

Reproduction

[edit, thanks @jelbourn]
https://stackblitz.com/edit/angular-xpwhup?file=src/app/table-sorting-example.ts

Expected Behavior

The sorting of strings should work as one expects when values are strings.

Actual Behavior

The sortingDataAccessor won't sort a string column correctly if one or more records contain a number only eg '1'.

Ex: ['One' ,'2', 'Three']

Suggested change

Use typeof value === 'number' instead of _isNumberValue perhaps, or something more elaborate?

Environment

  • Angular: 10
  • CDK/Material:10
@stnor stnor added the needs triage label Jul 30, 2020
@stnor stnor changed the title bug(table-data-source): Sorting of a string column(/property breaks if one record contains a number only bug(table-data-source): Sorting of a string column/property breaks if one record contains a number only Jul 30, 2020
@jelbourn
Copy link
Member

@jelbourn jelbourn commented Jul 30, 2020

Reproduction: https://stackblitz.com/edit/angular-xpwhup?file=src/app/table-sorting-example.ts

Confirmed that this happens and that it's weird

@Hugoer
Copy link

@Hugoer Hugoer commented Jul 31, 2020

Hi! I could try to take care of that myself. The solution I propose is to compare the data type after the call to _isNumberValue, if one of them is numeric and the other string, it would convert the numeric value to string, so if both are numeric the sort by number would be kept (faster ) and if not it would be ordered by text. I did a test on the stackblitz mentioned by jelbourn and it would work

Hugoer added a commit to Hugoer/components that referenced this issue Jul 31, 2020
Sort correctly when column information contains string and number values
Fixes angular#20140
Hugoer added a commit to Hugoer/components that referenced this issue Jul 31, 2020
Sort correctly when column information contains string and number values
Fixes angular#20140
Hugoer added a commit to Hugoer/components that referenced this issue Jul 31, 2020
Sort correctly when column information has string and numeric values

Fixes angular#20140
Hugoer added a commit to Hugoer/components that referenced this issue Jul 31, 2020
Sort correctly when column information has string and numeric values

Fixes angular#20140
Hugoer added a commit to Hugoer/components that referenced this issue Jul 31, 2020
Sort correctly when column information has string and numeric values
@jelbourn
Copy link
Member

@jelbourn jelbourn commented Aug 4, 2020

@andrewseguin thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.