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
? $sortHeader.sort
: (a, b) => {
const itemA = ascending ? a[sortKey] : b[sortKey]; const itemA = ascending ? a[sortKey] : b[sortKey];
const itemB = ascending ? b[sortKey] : a[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 - itemB;
}
return itemA return itemA
.toString() .toString()
.localeCompare(itemB.toString(), "en", { numeric: true }); .localeCompare(itemB.toString(), "en", { numeric: true });
} });
);
} }
} }
</script> </script>