AngularJS orderBy Filter Last Updated : 01 Aug, 2022 Comments Improve Suggest changes Like Article Like Report An orderBy Filter in AngularJS is used to sort the given array to the specific order. The default order of sorting the string is in alphabetical order whereas the numbers are numerically sorted. By default, all the items are sorted in ascending order, if the ordering sequence is not specified. Syntax: {{ orderBy_expression | orderBy : expression : reverse : comparator }} Parameter Values: expression: This parameter value can be used to determine the order while filtering the items. It can be the following types:Function: This function is invoked by passing each item as an argument & the returned value will be utilized for sorting the corresponding items.String: It can be an expression in AngularJS, that will be evaluated for every item & the output will be utilized to sort the item.Array: It can be utilized when we need to determine more than 1 object property that helps to organize the sorting order. The array item can contain both the string & function.reverse: It is an optional parameter that will be required to reverse the order of the array if its value is set to true.Example 1: This example describes the orderBy Filter in Angular JS by specifying the order sequence for the array item by name. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script> </head> <body> <div ng-app="myApp" ng-controller="orderCtrl"> <h1 style="color: green"> GeeksforGeeks </h1> <h3>AngularJS orderBy Filter</h3> <ul> <li ng-repeat= "x in customers | orderBy : 'name'"> {{x.name + ", " + x.city}} </li> </ul> </div> <script> var app = angular.module('myApp', []); app.controller('orderCtrl', function($scope) { $scope.customers = [{ "name": "Amber", "city": "ajmer" }, { "name": "lakshay ", "city": "vizag" }, { "name": "karan", "city": "London" }, { "name": "bhaskar", "city": "peshawar" }, ]; }); </script> <p>The array items are arranged by "name".</p> </body> </html> Output : Example 2: This example describes the AngularJS orderBy Filter illustrating an order by case when we go through gdp by "-" and "+" orderBy. HTML <!DOCTYPE html> <html> <head> <title> AngularJS orderBy Filters </title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> <style> .tabled { float: left; padding: 10px; } </style> </head> <body ng-app="orderByDemo"> <div style="text-align:center"> <h1 style="color:green"> GeeksforGeeks </h1> <h3> AngularJS orderBy Filter </h3> </div> <script> angular.module('orderByDemo', []) .controller('orderByController', ['$scope', function($scope) { $scope.countries = [{ name: 'SPAIN', states: '78', gdp: 5 }, { name: 'FRANCE', states: '46', gdp: 4 }, { name: 'PORTUGAL', states: '53', gdp: 3 }, { name: 'CHILE', states: '06', gdp: 2 }, { name: 'RUSSIA', states: '21', gdp: 1 }]; }]); </script> <div ng-controller="orderByController"> <table class="tabled"> <tr> <th>Name</th> <th>No of States</th> <th>GDP(descending)</th> </tr> <!-- orderBy Descending (-) --> <tr ng-repeat="country in countries | orderBy:'-gdp'"> <td>{{country.name}}</td> <td>{{country.states}}</td> <td>{{country.gdp}}</td> </tr> </table> <table class="tabled"> <tr> <th>Name</th> <th>No of States</th> <th>GDP(ascending)</th> </tr> <!-- orderBy Ascending (+) --> <tr ng-repeat="country in countries | orderBy:'gdp'"> <td>{{country.name}}</td> <td>{{country.states}}</td> <td>{{country.gdp}}</td> </tr> </table> </div> </body> </html> Output: Example 3: This example describes the AngularJS orderBy Filter that illustrates the sorting of the array items by country. HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body> <div ng-app="myApplication" ng-controller="orderCtrl"> <h1 style="color: green"> GeeksforGeeks </h1> <h3>AngularJS orderBy Filter</h3> <ul> <li ng-repeat= "x in sevenwonder | orderBy : '-country'"> {{x.name + ", " + x.country}} </li> </ul> </div> <script> var application = angular.module('myApplication', []); application.controller('orderCtrl', function($scope) { $scope.sevenwonder = [{ "name": "Great Wall of China", "country": "China" }, { "name": "Christ the Redeemer Statue", "country": "Brazil" }, { "name": "Machu Picchu", "country": "peru" }, { "name": "Chichen Itza ", "country": "Mexico" }, { "name": "The Roman Colosseum", "country": "Rome" }, { "name": "Taj Mahal", "country": "India" }, { "name": "Petra", "country": "Jordan" }]; }); </script> <p>The array items are sorted by "country".</p> </body> </html> Output: Reference: https://docs.angularjs.org/api/ng/filter/orderBy Comment More info A amberagrawal Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Filter Explore AngularJS BasicsAngularJS Tutorial 5 min read Introduction to AngularJS 4 min read Angular CLI | Angular Project Setup 3 min read AngularJS Expressions 2 min read AngularJS Modules 3 min read AngularJS ng-model Directive 4 min read AngularJS Data Binding 4 min read AngularJS Controllers 3 min read AngularJS | Scope 2 min read AngularJS Services 4 min read AngularJS | AJAX - $http 3 min read AngularJS | Tables 2 min read AngularJS Select Boxes 2 min read AngularJS SQL 3 min read AngularJS HTML DOM 2 min read AngularJS Events 3 min read AngularJS | Forms 3 min read AngularJS Form Validation 3 min read AngularJS | API 2 min read AngularJS and W3.CSS 2 min read AngularJS Includes 3 min read AngularJS Animations 1 min read AngularJS | Application 3 min read AngularJS DirectivesAngularJS Directives 9 min read AngularJS ng-app Directive 1 min read AngularJS ng-bind Directive 2 min read AngularJS ng-bind-html Directive 2 min read AngularJS ng-bind-template Directive 2 min read AngularJS ng-blur Directive 1 min read AngularJS ng-change Directive 2 min read AngularJS ng-checked Directive 2 min read AngularJS ng-class Directive 2 min read AngularJS ng-class-even Directive 2 min read AngularJS ng-class-odd Directive 2 min read AngularJS ng-click Directive 2 min read AngularJS ng-cloak Directive 2 min read AngularJS ng-controller Directive 2 min read AngularJS Directives Complete Reference 2 min read AngularJS FiltersAngularJS | Filters 7 min read AngularJS currency Filter 2 min read AngularJS | date Filter 2 min read AngularJS filter Filter 3 min read AngularJS json Filter 2 min read AngularJS limitTo Filter 2 min read AngularJS lowercase Filter 1 min read AngularJS number Filter 1 min read AngularJS orderBy Filter 4 min read AngularJs uppercase Filter 1 min read AngularJS Converting FunctionsAngularJS angular.lowercase() Function 2 min read AngularJS angular.uppercase() Function 1 min read AngularJS angular.forEach() Function 1 min read AngularJS Comparing FunctionsAngularJS angular.isArray() Function 2 min read AngularJS angular.isDate() Function 2 min read AngularJS angular.isDefined() Function 2 min read AngularJS angular.isElement() Function 2 min read AngularJS angular.isFunction() Function 2 min read AngularJS angular.isNumber() Function 2 min read AngularJS angular.isObject() Function 2 min read AngularJS | angular.isString() Function 1 min read AngularJS angular.isUndefined() Function 2 min read AngularJS angular.equals() Function 2 min read AngularJS angular.toJson() Function 2 min read AngularJS QuestionsHow to bundle an Angular app for production? 4 min read How to add many functions in one ng-click directive? 2 min read How to directly update a field by using ng-click in AngularJS ? 3 min read How to Add Dynamic Options for Multiple Selects Inside ng-repeat Directive ? 3 min read How to detect when an @Input() value changes in Angular? 3 min read How to open popup using Angular and Bootstrap ? 2 min read How to reload or re-render the entire page using AngularJS? 2 min read How to add input fields dynamically on button click in AngularJS ? 2 min read How to Create Button Dynamically with Click Event in Angular ? 2 min read How to use jQuery in Angular ? 2 min read AngularJS Examples 2 min read Like