Angularjs orderby filter example : Orderby clause is used to order the data as below:
Angularjs orderby filter Example & Syntax
OrderBy Desc Example
orderby Example : Descending
<div ng-app="" ng-init="myData=[{name:'John',city:'New York',id:25}, {name:'Mike',city:'Florida',id:12}, {name:'Minni',city:'London',id:2}, {name:'Sefali',city:'Sydney',id:8}, {name:'Maya',city:'Peris',id:22}, {name:'Kelly',city:'Beijing',id:3}]"> <table id="searchResults"> <tr><th>Name</th><th>City</th></tr> <tr ng-repeat="data in myData | orderBy:'-id'"> <td>{{data.id}}</td> <td>{{data.name}}</td> <td>{{data.city}}</td> </tr> </table> </div> |
OrderBy Asc Example
orderby Example : Ascending
<div ng-app="" ng-init="myData=[{name:'John',city:'New York',id:25}, {name:'Mike',city:'Florida',id:12}, {name:'Minni',city:'London',id:2}, {name:'Sefali',city:'Sydney',id:8}, {name:'Maya',city:'Peris',id:22}, {name:'Kelly',city:'Beijing',id:3}]"> <table id="searchResults"> <tr><th>Name</th><th>City</th></tr> <tr ng-repeat="data in myData | orderBy:'id'"> <td>{{data.id}}</td> <td>{{data.name}}</td> <td>{{data.city}}</td> </tr> </table> </div> |