feat(assist): 2 levels sort support
This commit is contained in:
parent
2de128ebcf
commit
bb8dee83fe
1 changed files with 10 additions and 4 deletions
|
|
@ -158,11 +158,17 @@ const getValue = function (obj, key) {
|
|||
const sortPaginate = function (list, filters) {
|
||||
const total = list.length;
|
||||
list.sort((a, b) => {
|
||||
const vA = getValue(a, filters.sort.key || "timestamp");
|
||||
const vB = getValue(b, filters.sort.key || "timestamp");
|
||||
return vA > vB ? 1 : vA < vB ? -1 : 0;
|
||||
const tA = getValue(a, "timestamp");
|
||||
const tB = getValue(b, "timestamp");
|
||||
return tA > tB ? 1 : tA < tB ? -1 : 0;
|
||||
});
|
||||
|
||||
if ((filters.sort.key || "timestamp") !== "timestamp") {
|
||||
list.sort((a, b) => {
|
||||
const vA = getValue(a, filters.sort.key);
|
||||
const vB = getValue(b, filters.sort.key);
|
||||
return vA > vB ? 1 : vA < vB ? -1 : 0;
|
||||
});
|
||||
}
|
||||
if (filters.sort.order) {
|
||||
list.reverse();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue