Merge pull request #356 from albertms10/datatable-sort-fix

fix(datatable): fix sort parameters
This commit is contained in:
Eric Liu 2020-10-24 15:03:09 -07:00 committed by GitHub
commit f22dfd52a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -166,22 +166,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>