Created
September 21, 2017 11:55
-
-
Save naveenrobo/87bf1e36f33386aa5973600886547a63 to your computer and use it in GitHub Desktop.
AngularJS : sorting - w3school
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-app="myApp" ng-controller="namesCtrl"> | |
<table border="1" width="100%"> | |
<tr> | |
<th ng-click="orderByMe('name')">Name</th> | |
<th ng-click="orderByMe('country')">Country</th> | |
</tr> | |
<tr ng-repeat="x in names | orderBy:myOrderBy"> | |
<td>{{x.name}}</td> | |
<td>{{x.country}}</td> | |
</tr> | |
</table> | |
</div> | |
<script> | |
angular.module('myApp', []).controller('namesCtrl', function($scope) { | |
$scope.names = [ | |
{name:'Jani',country:'Norway'}, | |
{name:'Carl',country:'Sweden'}, | |
{name:'Margareth',country:'England'}, | |
{name:'Hege',country:'Norway'}, | |
{name:'Joe',country:'Denmark'}, | |
{name:'Gustav',country:'Sweden'}, | |
{name:'Birgit',country:'Denmark'}, | |
{name:'Mary',country:'England'}, | |
{name:'Kai',country:'Norway'} | |
]; | |
$scope.orderByMe = function(x) { | |
$scope.myOrderBy = x; | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment