I'm using pagination for my data set and now I'm trying to sort it but the sort function sorts only the current page's records. I want to sort the entire data set not only the current page. Is there any possible way to do it? Thanks.
Here is my controller.js
angular.module("app").controller("billetController", function($scope, billetService) {
var self = this;
self.billets = [];
$scope.allCandidates = [];
$scope.aCandidates = [];
$scope.totalItems = 0;
$scope.sortType = 'statutBillet'; // set the default sort type
$scope.sortReverse = false; // set the default sort order
getBillets();
function getBillets() {
billetService.getBillets()
.then(
function(d) {
console.log(d);
self.billets = d;
$scope.totalItems = self.billets.length;
$scope.$watch("currentPage", function() {
console.log($scope.currentPage);
$scope.aCandidates = self.billets.slice(
($scope.currentPage - 1) * $scope.itemsPerPage,
$scope.currentPage * $scope.itemsPerPage
);
});
},
function(errResponse) {
console.error('Error while fetching ');
}
);
}
$scope.currentPage = 1;
$scope.itemsPerPage = 50;
function setPagingData(page, allCandidates) {
var pagedData = allCandidates.toString().slice(
(page - 1) * $scope.itemsPerPage,
page * $scope.itemsPerPage
);
$scope.aCandidates = pagedData;
}
console.log($scope.allCandidates);
});
and my table in view.jsp :
<div ng-controller="billetController">
<table class="table table-hover">
<thead>
<th>ID</th>
<th>
<a href="#" ng-click="sortType = 'statutBillet'; sortReverse = !sortReverse">
Statut
<span ng-show="sortType == 'statutBillet' && !sortReverse" class="fa fa-caret-down"></span>
<span ng-show="sortType == 'statutBillet' && sortReverse" class="fa fa-caret-up"></span>
</a></th>
<th>Priorité</th>
<th>Impact</th>
<th>Resumé</th>
<th>Date de création</th>
</thead>
<tbody>
<tr ng-repeat="billet in aCandidates | orderBy:sortType:sortReverse">
<td>{{ billet.idBillet }}</td>
<td>{{ billet.statutBillet }}</td>
<td>{{ billet.prioriteBillet }}</td>
<td>{{ billet.impactBillet }}</td>
<td>{{ billet.resumeBillet }}</td>
<td>{{ billet.dateCreation | date:'yyyy-MM-dd HH:mm:ss' }}</td>
</tr>
</tbody>
</table>
<uib-pagination total-items="totalItems" ng-model="currentPage" items-per-page="itemsPerPage"></uib-pagination>
</div>