From 1dceaa2e01c5575ed131a375b9184eee4af8a7a1 Mon Sep 17 00:00:00 2001 From: Sean Hughes Date: Fri, 3 Jan 2025 16:30:34 -0500 Subject: [PATCH] Fix case sensitivity of sort in DataTable --- .changeset/odd-cups-attend.md | 5 +++++ .../lib/unsorted/viz/table/_DataTable.svelte | 22 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 .changeset/odd-cups-attend.md diff --git a/.changeset/odd-cups-attend.md b/.changeset/odd-cups-attend.md new file mode 100644 index 0000000000..fba657b781 --- /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 0fba033858..cfa8857a47 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 = {};