I am new in AngularJS...I created a filter on an output data. Next I need to sort those array data based on a dropdown selected item. I am not getting it.The filter processing is done in the 3rd directive. Any help is appreciated.
$scope.options=[
{label: 'Name', value:1,submenu:null},
{label: 'Age', value:2,submenu:null},
{label: 'Country', value:3,submenu:[
{label:'India',value:1},
{label:'China',value:2},
{label:'Singapore',value:3},
{label:'London',value:4}
]}
];
<select ng-model="model1" ng-options="opt as opt.label for opt in options">
</select>
here is the plunker http://plnkr.co/edit/BFEJQo8Zp2eukdgP9BKM?p=preview
Try using a custom ordering in ng-repeat.
<div ng-repeat="detail in details | orderBy : sortingOrder : reverse" ng-show="showResults">
{{detail.Fname | uppercase}}
{{detail.Lname}}
{{detail.age}}
{{detail.sex}}
{{detail.place}}
</div>
script
$scope.search = function() {
$scope.reverse = '';
$scope.showResults = true;
if ($scope.model1.label === 'Age') {
$scope.sortingOrder = 'age';
} else if ($scope.model1.label === 'Name') {
$scope.sortingOrder = 'Fname';
} else if ($scope.model1.label === 'Country') {
$scope.sortingOrder = 'place';
}
else if ($scope.model1.label === 'Gender') {
console.log($scope.user.sex1);
if($scope.user.sex1 === 'male')
{
$scope.reverse = true;
}
else if($scope.user.sex1 === 'female')
{
$scope.reverse = false;
}
$scope.sortingOrder = 'sex';
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.