AngularJS: how to order by dropdown
How to sort dropdown in angularjs?
HTML
<div ng-app="myApp" ng-controller="Ctrl">
<select ng-options="value as value for value in sort(charityList)" ng-model="reportSearch.charityId">
<option value="">All Charity</option>
</select>
</div>
JavaScript
angular.module('myApp', [])
.controller('Ctrl', function($scope) {
$scope.charityList = {
"1": "softweb charity",
"2": "charity 1",
"3": "charity update",
"4": "Engagement1 Name",
"6": "United Way Enagagement",
"7": "Indian Noble Charity"
}
$scope.sort = function(list) { //returns an array : ["charity 1","charity update","Engagement1 Name","Indian Noble Charity","softweb charity", "United Way Enagagement"]
return $.map(list, function(el) { return el }).sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
}
});