mirror of
https://github.com/grafana/grafana.git
synced 2025-02-03 12:11:09 -06:00
better sort function
This commit is contained in:
parent
1609c07fb2
commit
39be5959b8
@ -7,18 +7,14 @@ export function sortTableData(data: TableData, sortIndex?: number, reverse = fal
|
||||
if (isNumber(sortIndex)) {
|
||||
const copy = {
|
||||
...data,
|
||||
rows: data.rows.map((row, index) => {
|
||||
return row;
|
||||
rows: [...data.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);
|
||||
}),
|
||||
};
|
||||
|
||||
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) {
|
||||
copy.rows.reverse();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user