【发布时间】:2023-03-26 18:50:01
【问题描述】:
我正在为我的数据集使用分页,现在我正在尝试对其进行排序,但排序功能仅对当前页面的记录进行排序。我想对整个数据集进行排序,而不仅仅是当前页面。有什么可能的方法吗?谢谢。
这是我的 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);
});
还有我在 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>
【问题讨论】:
标签: angularjs sorting angular-ui-bootstrap