Skip to content

orderBy() does not sort correctly with non-English characters (e.g. "Š") #2006

@uniquexor

Description

@uniquexor

Environment

No response

Reproduction

Given the following items:

[
  { name: 'A' },
  { name: 'B' },
  { name: 'Š' },
  { name: 'T' },
  { name: 'U' }
]

Using:
Item.query().orderBy('name', 'asc').get()

Returns:
[ 'A', 'B', 'T', 'U', 'Š' ]

Expected result (Lithuanian alphabetical order):
[ 'A', 'B', 'Š', 'T', 'U' ]

Describe the bug

When using the orderBy() method in pinia-orm, sorting fields that contain non-English characters specifically Lithuanian letters such as "Š" does not respect the correct alphabetical order according to the Lithuanian locale.

Expected Behavior:
Sorting with orderBy() should respect locale-aware collation (e.g., using localeCompare() under the hood, with the option to specify a locale such as 'lt' for Lithuanian).

Workaround:
Currently, the only way to achieve correct sorting is to manually sort the results after .get():

Item.query().get().slice().sort((a, b) =>
  a.name.localeCompare(b.name, 'lt')
)

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions