orderBy multiple fields in Angular
Solution 1:
Please see this:
http://jsfiddle.net/JSWorld/Hp4W7/32/
<div ng-repeat="division in divisions | orderBy:['group','sub']">{{division.group}}-{{division.sub}}</div>
Solution 2:
If you wants to sort on mulitple fields inside controller use this
$filter('orderBy')($scope.property_list, ['firstProp', 'secondProp']);
See also https://docs.angularjs.org/api/ng/filter/orderBy
Solution 3:
<select ng-model="divs" ng-options="(d.group+' - '+d.sub) for d in divisions | orderBy:['group','sub']" />
User array instead of multiple orderBY
Solution 4:
Sorting can be done by using 'orderBy' filter in angular.
Two ways: 1. From view 2. From controller
- From view
Syntax:
{{array | orderBy : expression : reverse}}
For example:
<div ng-repeat="user in users | orderBy : ['name', 'age'] : true">{{user.name}}</div>
- From controller
Syntax:
$filter.orderBy(array, expression, reverse);
For example:
$scope.filteredArray = $filter.orderBy($scope.users, ['name', 'age'], true);
Solution 5:
There are 2 ways of doing AngularJs filters, one in the HTML using {{}} and one in actual JS files...
You can solve you problem by using :
{{ Expression | orderBy : expression : reverse}}
if you use it in the HTML or use something like:
$filter('orderBy')(yourArray, yourExpression, reverse)
The reverse is optional at the end, it accepts a boolean and if it's true, it will reverse the Array for you, very handy way to reverse your Array...