Angularjs orderby filter example


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

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
</head>

<body>
<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>

</body>
</html>

Try it »

OrderBy Asc Example

orderby Example : Ascending

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
</head>

<body>
<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>

</body>
</html>

Try it »


Add Comment

📖 Read More


Advertisements