Angularjs: ng-options: how to order options with a group and non-groups

I have my group using ng-options, which looks like

<select ng-model="selected" ng-options="d.title group by d.group for d in data"></select> 

Here are my details

 $scope.data = [ { group:"", title:"No GroupA" }, { group:"Group_1", title:"1" }, { group:"", title:"No GroupB" }, { group:"Group_2", title:"2" }, { group:"", title:"No GroupC" } ]; 

the problem is that this creates an optgroup at the bottom of this selection menu, and not in the same order as in my data list.

 No GroupA No GroupB No GroupC [Group_1] 1 [Group_2] 2 

I want to create:

 No GroupA [Group_1] 1 No GroupB [Group_2] 2 No GroupC 

Here is the fiddle

Thanks!

+5
source share
1 answer

As far as I know, you cannot have mixed choices within and without groups.

You can create a common group for these parameters:

 <select ng-model="selected" ng-options="d.title group by (d.group ==='' ? 'No_Group' : d.group) for d in data"> </select> 

Here is your updated fiddle .

+4
source

Source: https://habr.com/ru/post/1205826/


All Articles