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

DataTable: sortable attribute not sorting lexicographically with string data column #4903

Closed
JeffreyStevens opened this issue Sep 7, 2023 · 1 comment
Labels
Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior

Comments

@JeffreyStevens
Copy link

Describe the bug

When using the DataTable sort icon to sort ascending or descending two data items do not sort lexicographically. In our Data.js file we have 4 items and they should sort ascending and descending as follows:

Expected:
["123","4ARD4","7000269851","SP00500127"] when ascending
["SP00500127","7000269851","4ARD4","123"] when descending

Actual (Bug):
["4ARD4","123","7000269851","SP00500127"] when ascending
["SP00500127","7000269851","123","4ARD4"] when descending

Reproducer

https://codesandbox.io/s/primereact-demo-forked-72rtw4?file=/src/App.js

PrimeReact version

9.6.2

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

Chrome

Steps to reproduce the behavior

Sort on first column that says "Code"

Expected behavior

No response

@JeffreyStevens JeffreyStevens added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Sep 7, 2023
@melloware
Copy link
Member

Its using your Locale handling of String Sorting.

 static localeComparator(locale) { 
     //performance gain using Int.Collator. It is not recommended to use localeCompare against large arrays. 
     return new Intl.Collator(locale, { numeric: true }).compare; 
 } 

try it out...

new Intl.Collator('en-US', { numeric: true }).compare("123", "4ARD4");

image

@melloware melloware added Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Sep 8, 2023
@melloware melloware closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: By Design The behavior in the issue is by design and the component exhibits the expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants