FOO
FOO

Reputation: 612

Angular: Sort by list of properties with mixed ASC and DESC

I have an ng-repeat and I'm trying to get a specific order. I see that I can order using a list of properties:

ng-repeat="client in clients | orderBy: ['isOpen', 'lastAccessTime']"

My question is, how do I configure ascending and descending?

I want the primary sort on isOpen with DESC, and secondary sort on lastAccessTime with ASC. How can I achieve this in my ng-repeat?

EDIT: I tried this below but, but when two items are both isOpen, the highest lastAccessTime is not on top:

ng-repeat="client in clients | orderBy: 'isOpen':true | orderBy: 'lastAccessTime'"

Upvotes: 2

Views: 1151

Answers (2)

dimirc
dimirc

Reputation: 6605

You can use an array and optionally prefixed with + or - to control ascending or descending sort order

ng-repeat="client in clients | orderBy: ['isOpen','-lastAccessTime']"

Upvotes: 1

Colin Brock
Colin Brock

Reputation: 21565

You can prefix the property name with a + or - to indicate either ascending or descending order, as specified in the documentation for orderBy.

Upvotes: 5

Related Questions