angular.Array.orderBy

Description

Orders array by the expression predicate.

Note: this function is used to augment the Array type in angular expressions. See angular.Array for more info.

Dependencies

Usage

angular.Array.orderBy(array, expression[, reverse]);

Parameters

Returns

{Array}

Sorted copy of the source array.

Example

<div ng:init="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}]"></div> <pre>Sorting predicate = {{predicate}}</pre> <hr/> <table ng:init="predicate='-age'"> <tr> <th><a href="" ng:click="predicate = 'name'">Name</a> (<a href ng:click="predicate = '-name'">^</a>)</th> <th><a href="" ng:click="predicate = 'phone'">Phone</a> (<a href ng:click="predicate = '-phone'">^</a>)</th> <th><a href="" ng:click="predicate = 'age'">Age</a> (<a href ng:click="predicate = '-age'">^</a>)</th> <tr> <tr ng:repeat="friend in friends.$orderBy(predicate)"> <td>{{friend.name}}</td> <td>{{friend.phone}}</td> <td>{{friend.age}}</td> <tr> </table>