Commit 39be5959 by ryan

better sort function

parent 1609c07f
...@@ -7,18 +7,14 @@ export function sortTableData(data: TableData, sortIndex?: number, reverse = fal ...@@ -7,18 +7,14 @@ export function sortTableData(data: TableData, sortIndex?: number, reverse = fal
if (isNumber(sortIndex)) { if (isNumber(sortIndex)) {
const copy = { const copy = {
...data, ...data,
rows: data.rows.map((row, index) => { rows: [...data.rows].sort((a, b) => {
return row; a = a[sortIndex];
b = b[sortIndex];
// Sort null or undefined separately from comparable values
return +(a == null) - +(b == null) || +(a > b) || -(a < b);
}), }),
}; };
copy.rows.sort((a, b) => {
a = a[sortIndex];
b = b[sortIndex];
// Sort null or undefined separately from comparable values
return +(a == null) - +(b == null) || +(a > b) || -(a < b);
});
if (reverse) { if (reverse) {
copy.rows.reverse(); copy.rows.reverse();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment