Skip to content

fix(table-sort): use locale-aware alphanumeric string comparison - #344

Merged
hjalmers merged 1 commit into
release/rcfrom
fix/table-sort-locale-compare
Oct 3, 2026
Merged

hjalmers merged 1 commit into
release/rcfrom
fix/table-sort-locale-compare

Conversation

@hjalmers

@hjalmers hjalmers commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Summary

Backport of 8a1b2af from main (shipped in 5.1.x) to the 5.0.0-rc line, so users on Angular 12–15 get the same sorting behaviour without upgrading.

sortOnMultipleKeys in projects/core/src/lib/utilities/utilities.ts now:

  • compares string pairs with localeCompare(…, undefined, { numeric: true, sensitivity: 'base' }) — natural alphanumeric order (Item 2 before Item 10), case-insensitive, and å/ä/ö ordered by the end user's locale rules instead of UTF-16 code units;
  • treats undefined like null (sorted last);
  • continues to the next sort key when values are equal, instead of returning 0 (fixes multi-key tiebreaking broken since rc.20's "handle null and equal values").

Behaviour is identical to main; the only textual difference is prettier line wrapping per this branch's config. No public API changes.

Before / after (ascending, single key)

Input rc.20 this PR (sv-SE runtime locale)
Örebro, Ängelholm, Åre, Alingsås, Zürich Alingsås, Zürich, Ängelholm, Åre, Örebro Alingsås, Zürich, Åre, Ängelholm, Örebro
Item 10, Item 2, Item 1, Item 20 Item 1, Item 10, Item 2, Item 20 Item 1, Item 2, Item 10, Item 20
banana, Apple, cherry Apple, banana, cherry Apple, banana, cherry

Note: no locale is passed, so collation follows the browser's default locale (same as main). In an en browser, Å/Ä/Ö are treated as accented A/O and interleave with them.

Verification

  • npm run build (ng-packagr) succeeds.
  • eslint and prettier --check pass on the changed file.
  • An assertion script importing the real sortOnMultipleKeys passes under both en-US and sv-SE runtime locales (natural numeric order, case-insensitivity, null/undefined last, multi-key tiebreak with mixed asc/desc, numbers still numeric, Å/Ä/Ö after Z under Swedish collation).
  • No spec file added: the core project on this branch has no test target (main moved to vitest later), so main's utilities.spec.ts changes could not run here.

Release

Merging into release/rc triggers the existing main.yml workflow, where semantic-release publishes 5.0.0-rc.21 to the npm rc dist-tag (the commit is a fix:).

🤖 Generated with Claude Code

https://claude.ai/code/session_01QHoGUgdEaYbnkn84rpkGHw


Generated by Claude Code

Backport of 8a1b2af from main to the 5.0.0-rc line. Compare string values
with localeCompare (numeric, case-insensitive) so e.g. 'Item 2' sorts before
'Item 10' and å/ä/ö follow the user's locale rules, treat undefined like null,
and continue to the next sort key when values are equal instead of
returning 0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHoGUgdEaYbnkn84rpkGHw
@hjalmers
hjalmers merged commit c3a9778 into release/rc Oct 3, 2026
1 of 2 checks passed
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 5.0.0-rc.21 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants