AngularJS - ngOptions: How to order by Group Name and then by Label AngularJS - ngOptions: How to order by Group Name and then by Label angularjs angularjs

AngularJS - ngOptions: How to order by Group Name and then by Label


orderBy can take an array of multiple parameters to order by. So you can do:

c as c.label group by c.group for c in data | orderBy:['group','label']

Here is a fiddle


It seems like orderBy would work exactly like you want.

Just take your expression and add the orderBy at the end:

c as c.label group by c.group for c in data | orderBy:'label'

This will first order the data array by the value of each item's label property, and then group them. Because the data will have been ordered correctly, each group will show up sorted correctly.

Here's a fiddle.

Note how the initial array is defined in backwards order, but is sorted correctly in each group in the select.