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 sorts string values as numbers #34

Open
2 of 4 tasks
lroal opened this issue Feb 7, 2025 · 0 comments
Open
2 of 4 tasks

Datatable sorts string values as numbers #34

lroal opened this issue Feb 7, 2025 · 0 comments
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team

Comments

@lroal
Copy link

lroal commented Feb 7, 2025

Describe the bug

When sorting the an array of string values 11, 1A and 2A, one expects the order to be:
11
1A
2A

This is in compliance with the default string sort in javascript:

const values = ['1A','2A','11'];
const sorted = values.sort((a, b) => {
  return a.localeCompare(b);
});
console.dir(JSON.stringify(sorted));
//["11","1A","2A"]

However, when sorting with column in Datatable, the sequence becomes:
1A
2A
11

It seems like Datatable uses Intl.Collator with numeric=true for sorting. This yields incorrect sort order for alphanumeric strings.

Pull Request Link

No response

Reason for not contributing a PR

  • Lack of time
  • Unsure how to implement the fix/feature
  • Difficulty understanding the codebase
  • Other

Other Reason

No response

Reproducer

https://stackblitz.com/edit/attxsqgh-g42npo1p?file=src%2FApp.vue

Environment

Stackblitz

Vue version

3.2.45

PrimeVue version

4.2.5

Node version

No response

Browser(s)

No response

Steps to reproduce the behavior

Run the stackblitz. Click on the column header to sort.
Verify incorrect sort order.

Expected behavior

Sort it in the following order:
11
1A
2A

@mertsincan mertsincan added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
None yet
Development

No branches or pull requests

2 participants