modify Ox.sort so that empty, null or undefined volumes come last, regardless of sort order (fixes # 727)

This commit is contained in:
rolux 2012-03-31 23:00:05 +02:00
parent 4a09d329c8
commit b03393bc0c

View file

@ -246,7 +246,7 @@ Ox.api = function(items, options) {
};
} else if (Ox.isArray(items[0][key])) {
sort[key] = function(value) {
return value.join(', ')
return value.join(', ');
};
}
});
@ -399,15 +399,24 @@ Ox.range = function() {
// pad leading numbers, make lowercase,
// and remove leading non-word characters
arr.forEach(function(val, i) {
sort[val] = Ox.isString(arr_[i])
? (
var val_ = arr_[i];
if (
Ox.isEmpty(val_)
|| Ox.isNull(val_)
|| Ox.isUndefined(val_)
) {
sort[val] = null;
} else if (Ox.isString(val_)) {
sort[val] = (
matches[val]
? arr_[i].replace(
? val_.replace(
matches[val], Ox.pad(matches[val], len)
)
: arr_[i]
).toLowerCase().replace(/^\W+/, '')
: arr_[i];
: val_
).toLowerCase().replace(/^\W+/, '');
} else {
sort[val] = val_;
}
});
return sort;
}
@ -465,13 +474,16 @@ Ox.range = function() {
return v[key];
}), fn[key]);
});
Ox.print('VALS::::', values)
return arr.sort(function(a, b) {
var aValue, bValue, index = 0, key, ret = 0;
while (ret == 0 && index < length) {
key = by[index].key;
aValue = values[key][a[key]];
bValue = values[key][b[key]];
if (aValue < bValue) {
if ((aValue === null) != (bValue === null)) {
ret = aValue === null ? 1 : -1;
} else if (aValue < bValue) {
ret = by[index].operator == '+' ? -1 : 1;
} else if (aValue > bValue) {
ret = by[index].operator == '+' ? 1 : -1;