서버 쪽 정렬 및 페이지 매김을 구현하고 있으며 사용자가있는 현재 페이지를 전달해야합니다. 그러면 정렬되어 첫 번째 페이지와 다른 페이지 페이지 (예 : 5 페이지의 "최소 득표 수"정렬은 5 페이지의 1 페이지에서 찾은 결과를 나타내지 않지만 5 페이지에있는 결과를 보여줍니다). 기본적으로, 나는 정렬을해야하지만 현재 페이지를 가져 오는 방법을 알아낼 수는 없습니다.AngularJS 페이지 매기기 - 현재 페이지 가져 오기 및 컨트롤러로 전달
서버 측의 페이징이 문제없이 작동하고 있으며 여기에 간단한 내용이 누락되었다고 생각됩니다.
HTML (I이 사용자 정의 지시어 사용하고 있음을 유의하시기 바랍니다 : https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination) : 그래서
var currPage = $scope.currentPage;
currPage
<tr dir-paginate="article in articles | itemsPerPage:articlesPerPage" total-items="totalArticles" current-page="currentPage">
<td>
<div class="col-md-1 voting well">
<div class="votingButton" ng-click="upVote(articlevote);">
<i class="glyphicon glyphicon-chevron-up"></i>
</div>
<div class="badge badge-inverse">
<div>{{article.articlevotes}}</div>
</div>
<div class="votingButton" ng-click="downVote(articlevote);">
<i class="glyphicon glyphicon-chevron-down"></i>
</div>
</div>
</td>
<td>{{article.articletitle}}</td>
<td>{{article.articlecategoryid}}</td>
<td><a ng-href="#article/{{article.id}}/{{article.articlelink}}">{{article.articletitle}}</a></td>
</tr>
</table>
<dir-pagination-controls on-page-change="pageChanged(newPageNumber)"></dir-pagination-controls>
컨트롤러
$scope.articles = [];
$scope.totalArticles = 0;
$scope.articlesPerPage = 10; // this should match however many results your API puts on one page
$scope.currentPage = 1;
// sort options
$scope.sortoptions = [
{
label: 'Most Votes',
value: 'articlevotes desc',
},
{
label: 'Least Votes',
value: 'articlevotes asc',
}
];
var sortBy = $scope.sortoptions[0].value;
var currPage = $scope.currentPage; // Get current page
console.log(currPage);
// Initial page load
getResultsPage(1, sortBy);
$scope.update = function (articleSortOrder) {
// get value of sort and log it
console.log(articleSortOrder.value);
sortBy = articleSortOrder.value;
// log current page and pass as parameter
console.log(currPage);
getResultsPage(currPage, sortBy); // need to make dynamic so it gets current page
}
$scope.pageChanged = function (newPage) {
getResultsPage(newPage, sortBy);
};
function getResultsPage(pageNumber, sortorder) {
// currently skipping by page number * articles per page
pfcArticles.query({ $skip: (pageNumber - 1) * $scope.articlesPerPage, $top: $scope.articlesPerPage, $orderby: sortorder, $inlinecount: 'allpages' }, function (data) {
$scope.articles = data.results;
$scope.totalArticles = data.count; // Can change to hard number to reduce total items instead of LimitTo
});
}
콘솔에 $ scope.currentPage가 기록되어 있으면 숫자 1 만 반환됩니다. 일부 페이징 선상에 나열된 코드를 시도했지만 plunker가 페이지 번호를 올바르게 반환하지만 광산은 반환하지 않습니다. – Kode
보기 코드에'dir-paginate' 및'dir-pagination-controls' 지시어가 보이지 않습니다. 질문을 보여주기 위해 업데이트 할 수 있습니까? –
추가됨, currentPage가 전달되지 않는 것 같습니다. 기본 angleUI 페이지 매김의 예제를 만들었지 만 같은 문제가있는 것으로 보입니다. – Kode