fix sorting of undefined values with multiple columns

This commit is contained in:
Christian Vette 2014-12-22 21:06:01 +01:00
parent 31c7973763
commit e45407256e
1 changed files with 7 additions and 6 deletions

View File

@ -347,18 +347,19 @@ Memory.prototype.all = function all(model, filter, callback) {
});
function sorting(a, b) {
var undefinedA, undefinedB;
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) {
return 0;
}
if (b[this[i].key] === undefined || a[this[i].key] > b[this[i].key]) {
if (undefinedB || a[this[i].key] > b[this[i].key]) {
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 0;
}
};