fix sorting of undefined values with multiple columns
This commit is contained in:
parent
31c7973763
commit
e45407256e
|
@ -347,18 +347,19 @@ Memory.prototype.all = function all(model, filter, callback) {
|
||||||
});
|
});
|
||||||
|
|
||||||
function sorting(a, b) {
|
function sorting(a, b) {
|
||||||
|
var undefinedA, undefinedB;
|
||||||
|
|
||||||
for (var i = 0, l = this.length; i < l; i++) {
|
for (var i = 0, l = this.length; i < l; i++) {
|
||||||
|
undefinedB = b[this[i].key] === undefined && a[this[i].key] !== undefined;
|
||||||
|
undefinedA = a[this[i].key] === undefined && b[this[i].key] !== undefined;
|
||||||
|
|
||||||
if (a[this[i].key] === undefined && b[this[i].key] === undefined) {
|
if (undefinedB || a[this[i].key] > b[this[i].key]) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b[this[i].key] === undefined || a[this[i].key] > b[this[i].key]) {
|
|
||||||
return 1 * this[i].reverse;
|
return 1 * this[i].reverse;
|
||||||
} else if (a[this[i].key] === undefined || a[this[i].key] < b[this[i].key]) {
|
} else if (undefinedA || a[this[i].key] < b[this[i].key]) {
|
||||||
return -1 * this[i].reverse;
|
return -1 * this[i].reverse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue