Reputation: 1120
Having
<div class="item" data-ng-repeat="course in courses | filter:filterCourses | orderBy:predicate">...
and
$scope.predicate = function(course) {
//$scope.orderProp
};
what code do I need to put inside the predicate so I can
Notes:
Thank you
Answer: Here's what I ended up with http://jsfiddle.net/3hz2j8j7/
Upvotes: 0
Views: 163
Reputation: 370
in addition to Constantinos answer, I did a jsfiddle for you with your exact data. All the Angular magic is in
<div ng-repeat="course in courses|orderBy:[nonEmptyStartDate,orderProp]:true">
Where orderProp='title' so that first data are ordered by non empty date first and then by title. Please let us know .
Upvotes: 1
Reputation: 1208
OrderBy can accept a list of predicates (a bit like saying "order by A, then B"). So your first predicate will ensure that blank start dates go at the end, and your second one will use the value of orderProp:
<div ... orderBy:[nonEmptyStartDate, orderProp]">
$scope.nonEmptyStartDate = function(course) {
return course.startDate=="" ? 1 : 0;
}
Upvotes: 2