Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

example of directly calling $filter('orderBy') #7602

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,44 @@
</div>
</file>
</example>

<example>
<file name="controller.html">
<script>
function Ctrl($scope, $filter) {
$scope.friends =
[{name:'John', phone:'555-1212', age:10},
{name:'Mary', phone:'555-9876', age:19},
{name:'Mike', phone:'555-4321', age:21},
{name:'Adam', phone:'555-5678', age:35},
{name:'Julie', phone:'555-8765', age:29}]

$scope.order = function(predicate, reverse) {
$scope.friends = $filter('orderBy')($scope.friends, predicate, reverse);
}
$scope.order('-age',false) ;
}
</script>
<div ng-controller="Ctrl">
<table class="friend">
<tr>
<th><a href="" ng-click="reverse=false;order('name',false)">Name</a>
(
<a href="" ng-click="order('-name',false)">^</a>)</th>
<th><a href="" ng-click="reverse=!reverse;order('phone',reverse)">Phone Number</a>
</th>
<th><a href="" ng-click="reverse=!reverse;order('age',reverse)">Age</a>
</th>
</tr>
<tr ng-repeat="friend in friends">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
<td>{{friend.age}}</td>
</tr>
</table>
</div>
</file>
</example>
*/
orderByFilter.$inject = ['$parse'];
function orderByFilter($parse){
Expand Down