Skip to content

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

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

Closed
stnor opened this issue Jul 30, 2020 · 10 comments
Labels
area: cdk/table good first issue This issue is a good place to start for first time contributors to the project help wanted The team would appreciate a PR from the community to address this issue P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@stnor
Copy link

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 This issue needs to be triaged by the team 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

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

Confirmed that this happens and that it's weird

@jelbourn jelbourn added area: cdk/table good first issue This issue is a good place to start for first time contributors to the project help wanted The team would appreciate a PR from the community to address this issue P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs triage This issue needs to be triaged by the team labels Jul 30, 2020
@Hugoer
Copy link
Contributor

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 commented Aug 4, 2020

@andrewseguin thoughts?

@sahilmore-git
Copy link

fix(material/table): Sorting of a string column/property breaks if one record contains a number only

If the number is a string and in between strings we treat it as a number and group it at the start/end of the table based on it's ascending or descending. I have fixed the issue in my commit here and I think it will work properly.

Fixes #20140

@sahilmore-git
Copy link

@jelbourn Please correct me if I am wrong.

@sahilmore-git
Copy link

@stnor any views ??

@stnor
Copy link
Author

stnor commented Aug 20, 2021

LGTM

sahilmore-git added a commit to sahilmore-git/components that referenced this issue Aug 26, 2021
…e record contains a number only

If the number is a string and in between strings we treat it as a number and group it at the start/end of the table based on it's ascending or descending. I have fixed the issue in my commit here and I think it will work properly.

Fixes angular#20140
@Solonel
Copy link

Solonel commented Apr 20, 2022

Hello, I still have the issue on Angular 13.3.3, value 058233665663 is not place well
Example on mat table that didn't work :
https://stackblitz.com/edit/angular-mw3b1x?file=src/app/table-basic-example.html
Example with sort header that work :
https://stackblitz.com/edit/angular-fsdnz2?file=src/app/sort-overview-example.ts

@viniciusschuelter
Copy link

I probably fixed that #25444, @andrewseguin @crisbeto can u take a look?

@stnor stnor closed this as completed Feb 13, 2024
@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 Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: cdk/table good first issue This issue is a good place to start for first time contributors to the project help wanted The team would appreciate a PR from the community to address this issue P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
6 participants