diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-21 15:48:15 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-21 15:48:15 +0200 |
commit | 015668acfac041b977f1753161cba6d34ca7cb20 (patch) | |
tree | 3d67dc25082bb7a15f6c8f1e553f500e0c22059d /js | |
parent | 64fe77a3fc51c3eb88c5ffedfa75986a33fbc78e (diff) |
Fix sorting- fixes #382
Diffstat (limited to 'js')
-rw-r--r-- | js/filters/localeOrderBy_filter.js | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/js/filters/localeOrderBy_filter.js b/js/filters/localeOrderBy_filter.js index ecb2ad73..18e40c18 100644 --- a/js/filters/localeOrderBy_filter.js +++ b/js/filters/localeOrderBy_filter.js @@ -4,18 +4,6 @@ angular.module('contactsApp') if (!Array.isArray(array)) return array; if (!sortPredicate) return array; - var isString = function (value) { - return (typeof value === 'string'); - }; - - var isNumber = function (value) { - return (typeof value === 'number'); - }; - - var isBoolean = function (value) { - return (typeof value === 'boolean'); - }; - var arrayCopy = []; angular.forEach(array, function (item) { arrayCopy.push(item); @@ -23,13 +11,19 @@ angular.module('contactsApp') arrayCopy.sort(function (a, b) { var valueA = a[sortPredicate]; + if (angular.isFunction(valueA)) { + valueA = a[sortPredicate](); + } var valueB = b[sortPredicate]; + if (angular.isFunction(valueB)) { + valueB = b[sortPredicate](); + } - if (isString(valueA)) { + if (angular.isString(valueA)) { return !reverseOrder ? valueA.localeCompare(valueB) : valueB.localeCompare(valueA); } - if (isNumber(valueA) || isBoolean(valueA)) { + if (angular.isNumber(valueA) || angular.isBoolean(valueA)) { return !reverseOrder ? valueA - valueB : valueB - valueA; } |