Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in Web Technology by (47.6k points)

How to sort by using multiple fields at the same time in angular? fist by the group and then by sub-group for Example

$scope.divisions = [{'group':1,'sub':1}, {'group':2,'sub':10}, {'group':1,'sub':2},{'group':1,'sub':20},{'group':2,'sub':1}, {'group':2,'sub':11}];

I wanted to display this as

group: Sub-group

1 - 1

1 - 2

1 - 20

2 - 1

2 - 10

2 - 11

<select ng-model="divs" ng-options="(d.group+' - '+d.sub) for d in divisions | orderBy:'group' | orderBy:'sub'" />

1 Answer

+2 votes
by (106k points)
edited by

You can use the below-mentioned code to sort by using multiple fields at the same time in angular:-

Are you interested in learning Angularjs from the basics! Here's the right video for you on Angularjs provided by Intellipaat:

<div ng-repeat="division in divisions | orderBy:['group','sub']">{{division.group}}-{{division.sub}}

</div>

Check out this Angularjs online Course to enhance your career! 

Related questions

0 votes
1 answer
asked Aug 29, 2019 in Web Technology by Sammy (47.6k points)
0 votes
2 answers
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...