angularjs ui-select-choices dropdown aphabetical order depending on the input given angularjs ui-select-choices dropdown aphabetical order depending on the input given angularjs angularjs

angularjs ui-select-choices dropdown aphabetical order depending on the input given


If I understand you correctly, I think all you need to do is add

| orderBy:'Name'

<ui-select-choices repeat="item.Code as item in statesArray | filter:$select.search | orderBy:'Name'">{{item.Name}}</ui-select-choices>

Check out orderBy for more information


After digging a little and with Tomy's and KreepN's help, I found the answer. Here it is,

   <ui-select ng-model="model.states">     <ui-select-match placeholder="State">       {{$item.Name}}     </ui-select-match>     <ui-select-choices repeat="item.Code as item in statesArray | startsWith:$select.search | orderBy:'Code'">        {{item.Name}}     </ui-select-choices>   </ui-select>

startsWith Filter is as follows:

.filter('startsWith', function() {    return function(array,search) {        if(!_.isUndefined(array) && !_.isUndefined(search)) {            var matches = [];            for (var i = 0; i < array.length; i++) {                if (array[i].Name.toUpperCase().indexOf(search.toUpperCase()) === 0 &&                    search.length <= array[i].Name.length) {                    matches.push(array[i]);                }            }            return matches;        }    };});


I tried all the options above but I achieved the result only in this case.It works for me:

<ui-select-choices repeat="group in groups | filter: $select.search | orderBy:['name']">  {{ group.name }}</ui-select-choices>