angularjs - How do I code a custom ordering function in angular? -
having
<div class="item" data-ng-repeat="course in courses | filter:filtercourses | orderby:predicate">...
and
$scope.predicate = function(course) { //$scope.orderprop };
what code need put inside predicate can
- order same way default orderby:predicate order(not sure if makes sense)
- place empty course.startdate @ end of list
notes:
- course object different properties title, startdate, code
- $scope.orderprop contains value sort by: title, startdate, code. when startdate empty place items @ end of list still keep sorting date properly, start date "integer" later display ng-date in nicer form
thank you
answer: here's ended http://jsfiddle.net/3hz2j8j7/
orderby can accept list of predicates (a bit saying "order a, b"). first predicate ensure blank start dates go @ end, , second 1 use value of orderprop:
<div ... orderby:[nonemptystartdate, orderprop]"> $scope.nonemptystartdate = function(course) { return course.startdate=="" ? 1 : 0; }
Comments
Post a Comment