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 sortPaginate = function (list, filters) {
|
||||||
const total = list.length;
|
const total = list.length;
|
||||||
list.sort((a, b) => {
|
list.sort((a, b) => {
|
||||||
const vA = getValue(a, filters.sort.key || "timestamp");
|
const tA = getValue(a, "timestamp");
|
||||||
const vB = getValue(b, filters.sort.key || "timestamp");
|
const tB = getValue(b, "timestamp");
|
||||||
return vA > vB ? 1 : vA < vB ? -1 : 0;
|
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) {
|
if (filters.sort.order) {
|
||||||
list.reverse();
|
list.reverse();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue