Skip to content

Commit 2357d28

Browse files
Merge pull request michaelbromley#282 from axelduch/issue_#281_Pass_oldPageNumber_to_onPageChange_callback
Issue michaelbromley#281 pass old page number to on page change callback. Closes michaelbromley#281
2 parents 60c86e5 + 057eed2 commit 2357d28

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/directives/pagination/dirPagination.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,19 @@
309309

310310
function goToPage(num) {
311311
if (paginationService.isRegistered(paginationId) && isValidPageNumber(num)) {
312+
var oldPageNumber = scope.pagination.current;
313+
312314
scope.pages = generatePagesArray(num, paginationService.getCollectionLength(paginationId), paginationService.getItemsPerPage(paginationId), paginationRange);
313315
scope.pagination.current = num;
314316
updateRangeValues();
315317

316-
// if a callback has been set, then call it with the page number as an argument
318+
// if a callback has been set, then call it with the page number as the first argument
319+
// and the previous page number as a second argument
317320
if (scope.onPageChange) {
318-
scope.onPageChange({ newPageNumber : num });
321+
scope.onPageChange({
322+
newPageNumber : num,
323+
oldPageNumber : oldPageNumber
324+
});
319325
}
320326
}
321327
}

src/directives/pagination/dirPagination.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,15 @@ describe('dirPagination directive', function() {
644644
$scope.$apply();
645645
expect($scope.myCallback).toHaveBeenCalledWith(2);
646646
});
647+
648+
it('should pass the previous page number to the callback', function() {
649+
compileWithAttributes(' on-page-change="myCallback(oldPageNumber)" ');
650+
var pagination = containingElement.find('ul.pagination');
651+
652+
pagination.children().eq(3).find('a').triggerHandler('click');
653+
$scope.$apply();
654+
expect($scope.myCallback).toHaveBeenCalledWith(1);
655+
});
647656
});
648657

649658
describe('total-items attribute', function() {

0 commit comments

Comments
 (0)