mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
fix(datatable): fix sort parameters
This commit is contained in:
parent
8a65e463a1
commit
d0750d1fa2
1 changed files with 11 additions and 14 deletions
|
@ -128,22 +128,19 @@
|
|||
if ($sortHeader.sortDirection === "none") {
|
||||
sortedRows = rows;
|
||||
} else {
|
||||
sortedRows = [...rows].sort(
|
||||
$sortHeader.sort
|
||||
? $sortHeader.sort
|
||||
: (a, b) => {
|
||||
sortedRows = [...rows].sort((a, b) => {
|
||||
const itemA = ascending ? a[sortKey] : b[sortKey];
|
||||
const itemB = ascending ? b[sortKey] : a[sortKey];
|
||||
|
||||
if (typeof itemA === "number" && typeof itemB === "number") {
|
||||
if ($sortHeader.sort) return $sortHeader.sort(itemA, itemB);
|
||||
|
||||
if (typeof itemA === "number" && typeof itemB === "number")
|
||||
return itemA - itemB;
|
||||
}
|
||||
|
||||
return itemA
|
||||
.toString()
|
||||
.localeCompare(itemB.toString(), "en", { numeric: true });
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue