Joshua Ohana
Joshua Ohana

Reputation: 6121

ng-repeat with a filter and dual order by

I have an array of People I need to filter and order by against two criteria. My filter is simple in that if the name contains what they're typing let it through. For grouping, I want to group all of the people with clockedIn=1 first, and then within those two groups I want to order by last name.

My filter is working perfectly but I cannot seem to get orderBy to work at all no matter what I do...

Full jsfiddle: http://jsfiddle.net/joshuaohana/82k76uj0/1/, shows all helper functions and whatnot

The repeat I'm trying to setup:

<div ng-repeat="person in people | filter:nameFilterFn | orderBy: '+person.clockedIn' | orderBy:'-person.userLastName' ">
  <p>{{person.userName}}</p>
  <p>{{person.clockedIn}}</p>
</div>

For an ng-repeat, how do I...

  1. Filter against a function
  2. First sort by a boolean in the ng-repeat
  3. Secondly sort against the user's last name

Upvotes: 0

Views: 159

Answers (1)

SD.
SD.

Reputation: 9549

To sort by multiple field use this syntax:

<div ng-repeat="person in people | filter:nameFilterFn | orderBy: ['clockedIn', 'userLastName'] ">

To use reversed lastName use ['clockedIn', '-userLastName']

Updated fiddle here

Upvotes: 1

Related Questions