Skip to content

Commit

Permalink
fix(DataTable): handle null/undefined values when sorting (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
malinowskip authored Oct 11, 2021
1 parent 16c3779 commit d3eb146
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/DataTable/DataTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@
if (typeof itemA === "number" && typeof itemB === "number")
return itemA - itemB;
if ([itemA, itemB].every((item) => !item && item !== 0)) return 0;
if (!itemA && itemA !== 0) return ascending ? 1 : -1;
if (!itemB && itemB !== 0) return ascending ? -1 : 1;
return itemA
.toString()
.localeCompare(itemB.toString(), "en", { numeric: true });
Expand Down

0 comments on commit d3eb146

Please sign in to comment.