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") {
|
if ($sortHeader.sortDirection === "none") {
|
||||||
sortedRows = rows;
|
sortedRows = rows;
|
||||||
} else {
|
} else {
|
||||||
sortedRows = [...rows].sort(
|
sortedRows = [...rows].sort((a, b) => {
|
||||||
$sortHeader.sort
|
const itemA = ascending ? a[sortKey] : b[sortKey];
|
||||||
? $sortHeader.sort
|
const itemB = ascending ? b[sortKey] : a[sortKey];
|
||||||
: (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);
|
||||||
return itemA - itemB;
|
|
||||||
}
|
|
||||||
|
|
||||||
return itemA
|
if (typeof itemA === "number" && typeof itemB === "number")
|
||||||
.toString()
|
return itemA - itemB;
|
||||||
.localeCompare(itemB.toString(), "en", { numeric: true });
|
|
||||||
}
|
return itemA
|
||||||
);
|
.toString()
|
||||||
|
.localeCompare(itemB.toString(), "en", { numeric: true });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue