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

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.


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