Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case sensitivity of sort in DataTable #2971

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-cups-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/core-components': patch
---

Fix case sensitivity of sort in DataTable
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
Loading