0

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.

Community
  • 1
  • 1
abyrne85
  • 1,370
  • 16
  • 33

1 Answers1

2

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

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299