I have an object something like
x=[{a:1,b:2,c:3,d:'A'},{a:3,b:3,c:1,d:'C'},{a:2,b:1,c:2,d:'B'}]
View In HTML there are 3 buttons
<button ng-click="sortbyA()">
<button ng-click="sortbyB()">
<button ng-click="sortbyC()">
And a pop-up
<div ng-repeat='i in x | orderBy:sortBy'>
<table>
<tr><td>{{i.d}}</td></tr>
</table>
</div>
Angular JS Controller:
var app = angular.module("myApp", []);
app.controller("myCtrl", ['$compile', '$http', '$scope', function ($compile, $http, $scope) {
$scope.get_results=function(){
var response= $http.get();
response.success(function(){
$scope.sortBy='a';
});
}
$scope.sortbyA=function(){
$scope.sortBy='a';
}
$scope.sortbyB=function(){
$scope.sortBy='b';
}
$scope.sortbyC=function(){
$scope.sortBy='c';
}
}])
Use case is to populate data of table based different clicks(A,B,C) with their corresponding property in x
Eg: If click on B,table should have data sorted by attribute :b, If click on C,table should have data sorted by attribute :c