abyrne85
abyrne85

Reputation: 1450

Angular orderBy multiple fields with priority given to one field

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.

Upvotes: 0

Views: 1531

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136124

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

Upvotes: 2

Related Questions