From 63d210501039247a8181cce0001f5e4fdadeb1d5 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Tue, 16 Jul 2024 09:51:15 +0200 Subject: [PATCH] When sorting by name, use localeCompare() --- src/Components/Tailwind/Table.tsx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Components/Tailwind/Table.tsx b/src/Components/Tailwind/Table.tsx index ae982bb..e0100fa 100644 --- a/src/Components/Tailwind/Table.tsx +++ b/src/Components/Tailwind/Table.tsx @@ -101,6 +101,20 @@ export default function Table({ ); } +function compareNames(a: string, b: string): number { + return a.localeCompare(b); +} + +function compareDefault(a: any, b: any): number { + if (a > b) { + return 1; + } else if (a < b) { + return -1; + } else { + return 0; + } +} + function filterParticipants(participants: Participant[], data: SearchData) { const {searchValue, filters} = data; @@ -129,12 +143,10 @@ function filterParticipants(participants: Participant[], data: SearchData) { if (!ascending) { [b, a] = [a, b]; } - if (a[key] > b[key]) { - return 1; - } else if (a[key] < b[key]) { - return -1; + if (key === 'fullName') { + return compareNames(a.fullName, b.fullName); } else { - return 0; + return compareDefault(a[key], b[key]); } }); }