Angularjs table sorting example

Angularjs table sorting:

An orderBy filter is used to sort an Angularjs table. An orderBy is an angularjs filter which is used to orders or sort an array by an expression.


{{ expression | orderBy }}

Example explanation:

The ng-app directive initializes the application. We create a students object which is initialized by ng-init directive using JSON syntax. The ng-repeat directive will work as for-each loop and iterates over students object. The orderBy filter sort the data by student name.


    <title>AngularJS Table Sorting Example</title>    
    <script src=
     table, th , td {
      border: 1px solid grey;
      border-collapse: collapse;
      padding: 5px;
     table tr:nth-child(odd) {
      background-color: #f2f2f2;
     table tr:nth-child(even) {
      background-color: #ffffff;
      <h1>AngularJS Table Sorting Example.</h1>
      <div ng-app = "" 
           ng-init = "students=[{name:'Prabhjot',country:'US'},
         <p>Students with country name:</p>
              <tr ng-repeat = "student in students | orderBy : 'name'">
                 <td>{{ }}</td>
                 <td>{{ }}</td>

Try it:

AngularJS Table Sorting Example on

Please Share