From b03393bc0c4bcd2f288a94771c972359d5e6ec4b Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 31 Mar 2012 23:00:05 +0200 Subject: [PATCH] modify Ox.sort so that empty, null or undefined volumes come last, regardless of sort order (fixes # 727) --- source/Ox/js/Array.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index b4c4f64e..922a31ad 100644 --- a/source/Ox/js/Array.js +++ b/source/Ox/js/Array.js @@ -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;