From 3b98b0867c25ca275e4d1cf4452e3439f1e5991b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 18:58:10 +0000 Subject: [PATCH] fix(table-sort): use locale-aware alphanumeric string comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01QHoGUgdEaYbnkn84rpkGHw --- projects/core/src/lib/utilities/utilities.ts | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/projects/core/src/lib/utilities/utilities.ts b/projects/core/src/lib/utilities/utilities.ts index cf1f506..a9023eb 100644 --- a/projects/core/src/lib/utilities/utilities.ts +++ b/projects/core/src/lib/utilities/utilities.ts @@ -165,7 +165,7 @@ export let calculate = (data: Array, config: TableConfig) => { }; /** sortOnMultipleKeys - * @description Sort data on multiple keys + * @description Sort data on multiple keys with locale-aware alphanumeric comparison * @param {GtSortOrder} keys - array with sort config objects to sort on, data will be sorted according to array order * @returns sort function */ @@ -176,11 +176,21 @@ export const sortOnMultipleKeys = ( return (a, b) => { for (let i = 0; i < keys.length; i++) { const o = keys[i].key; - if (a[o] === b[o]) return 0; - if (a[o] === null) return 1; - if (b[o] === null) return -1; - if (a[o] > b[o]) return order[i]; - if (a[o] < b[o]) return -order[i]; + const aVal = a[o]; + const bVal = b[o]; + if (aVal === bVal) continue; + if (aVal === null || aVal === undefined) return 1; + if (bVal === null || bVal === undefined) return -1; + if (typeof aVal === 'string' && typeof bVal === 'string') { + const cmp = aVal.localeCompare(bVal, undefined, { + numeric: true, + sensitivity: 'base', + }); + if (cmp !== 0) return cmp * order[i]; + continue; + } + if (aVal > bVal) return order[i]; + if (aVal < bVal) return -order[i]; } return 0; };