diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-01-11 22:36:55 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-01-11 22:36:55 -0500 |
commit | 85fb4dd1ca54be22fbe393c27175b6fc78b7758b (patch) | |
tree | 5049b854070525b2eec99afae5722d2425cd7791 /assets/js/components | |
parent | d0dad82a278af213f56a279804d9f40348921b5e (diff) |
Improve auto-complete dropdown elements sorting
Diffstat (limited to 'assets/js/components')
-rw-r--r-- | assets/js/components/select-dropdown-autocomplete.js | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/assets/js/components/select-dropdown-autocomplete.js b/assets/js/components/select-dropdown-autocomplete.js index adf48470..42344be5 100644 --- a/assets/js/components/select-dropdown-autocomplete.js +++ b/assets/js/components/select-dropdown-autocomplete.js @@ -127,18 +127,29 @@ KB.component('select-dropdown-autocomplete', function(containerElement, options) function buildItems(items) { var elements = []; - var keys = Object.keys(items); - if (options.sortByKeys) { - keys.sort(); + for (var key in items) { + if (items.hasOwnProperty(key)) { + elements.push({ + 'class': 'select-dropdown-menu-item', + 'text': items[key], + 'data-label': items[key], + 'data-value': key + }); + } } - for (var i = 0; i < keys.length; i++) { - elements.push({ - 'class': 'select-dropdown-menu-item', - 'text': items[keys[i]], - 'data-label': items[keys[i]], - 'data-value': keys[i] + if (options.sortByKeys) { + elements.sort(function (a, b) { + var value1 = a['data-value'].toLowerCase(); + var value2 = b['data-value'].toLowerCase(); + return value1 < value2 ? -1 : (value1 > value2 ? 1 : 0); + }); + } else { + elements.sort(function (a, b) { + var value1 = a['data-label'].toLowerCase(); + var value2 = b['data-label'].toLowerCase(); + return value1 < value2 ? -1 : (value1 > value2 ? 1 : 0); }); } |