Angular orderBy multiple fields with priority given to one field

1.5k views Asked by At

Following on from a previous question on this topic (orderBy multiple fields in Angular), I'm wondering if it is possible to achieve this. Essentially, I want to orderBy multiple fields, but give priority to one of the fields if their value isn't null.

I'm using orderBy like so:

orderBy:['-sub','group']

From what I understand, the first item in the list of fields is given priority, but they are appearing at the bottom of the list.

1

There are 1 answers

2
Pankaj Parkar On

Then you should do something like this orderBy:['!-sub','group']"

Markup

<div class="test" ng-controller="Ctrl">
    <div ng-repeat="division in divisions | orderBy:['!-sub','group']">
       {{division.group}}-{{division.sub}}
    </div>
</div>

Updated Fiddle