Reputation: 39916
I use ng-repeat
to display a list of tasks:
<div class="task_container" ng-repeat="task in tasks | orderBy:weigth(task)">
<span >Task:<span><br><span>{{task.label}}</span>
</div>
Each task has some properties, and I have defined a weight function that sums up these properties:
function weight(task)
{
var weight_value = task.priority - task.difficulty + task.interest;
return weight_value;
}
However, when displaying the page, the tasks are not ordered at all.
Is there a better/correct way to achieve that ?
Upvotes: 0
Views: 83
Reputation: 7729
Just do that :
<div class="task_container" ng-repeat="task in tasks | orderBy:weigth">
<span >Task:<span><br><span>{{task.label}}</span>
</div>
A jsFiddle here : http://jsfiddle.net/pkozlowski_opensource/zjvsu/1/
Another complete post here : Custom sort function in ng-repeat
And attach your weight function to the $scope
Upvotes: 1