diff --git a/.changeset/odd-cups-attend.md b/.changeset/odd-cups-attend.md new file mode 100644 index 000000000..fba657b78 --- /dev/null +++ b/.changeset/odd-cups-attend.md @@ -0,0 +1,5 @@ +--- +'@evidence-dev/core-components': patch +--- + +Fix case sensitivity of sort in DataTable diff --git a/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte b/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte index 0fba03385..cfa8857a4 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte @@ -366,13 +366,21 @@ const forceTopOfAscending = (val) => val === undefined || val === null || (typeof val === 'number' && isNaN(val)); - const comparator = (a, b) => - (forceTopOfAscending(a[column]) && !forceTopOfAscending(b[column])) || a[column] < b[column] - ? -1 * sortModifier - : (forceTopOfAscending(b[column]) && !forceTopOfAscending(a[column])) || - a[column] > b[column] - ? 1 * sortModifier - : 0; + const comparator = (a, b) => { + const valA = a[column]; + const valB = b[column]; + + if (forceTopOfAscending(valA) && !forceTopOfAscending(valB)) return -1 * sortModifier; + if (forceTopOfAscending(valB) && !forceTopOfAscending(valA)) return 1 * sortModifier; + + // Ensure values are strings for case-insensitive comparison + const normalizedA = typeof valA === 'string' ? valA.toLowerCase() : valA; + const normalizedB = typeof valB === 'string' ? valB.toLowerCase() : valB; + + if (normalizedA < normalizedB) return -1 * sortModifier; + if (normalizedA > normalizedB) return 1 * sortModifier; + return 0; + }; if (groupBy) { const sortedGroupedData = {};