From fa729c6e3164ac6d27d7f475779edbd5d916b289 Mon Sep 17 00:00:00 2001 From: Andrew Shaffer Date: Mon, 15 Sep 2014 19:01:43 -0700 Subject: [PATCH 1/2] feat(pagination): add 'pageLabel' option --- src/pagination/pagination.js | 5 +++-- src/pagination/test/pagination.spec.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pagination/pagination.js b/src/pagination/pagination.js index f51b5eefe7..1df5382e57 100644 --- a/src/pagination/pagination.js +++ b/src/pagination/pagination.js @@ -5,7 +5,8 @@ angular.module('ui.bootstrap.pagination', ['ui.bootstrap.paging']) var maxSize = angular.isDefined($attrs.maxSize) ? $scope.$parent.$eval($attrs.maxSize) : uibPaginationConfig.maxSize, rotate = angular.isDefined($attrs.rotate) ? $scope.$parent.$eval($attrs.rotate) : uibPaginationConfig.rotate, forceEllipses = angular.isDefined($attrs.forceEllipses) ? $scope.$parent.$eval($attrs.forceEllipses) : uibPaginationConfig.forceEllipses, - boundaryLinkNumbers = angular.isDefined($attrs.boundaryLinkNumbers) ? $scope.$parent.$eval($attrs.boundaryLinkNumbers) : uibPaginationConfig.boundaryLinkNumbers; + boundaryLinkNumbers = angular.isDefined($attrs.boundaryLinkNumbers) ? $scope.$parent.$eval($attrs.boundaryLinkNumbers) : uibPaginationConfig.boundaryLinkNumbers, + pageLabel = angular.isDefined($attrs.pageLabel) ? function(idx) { return $scope.$parent.$eval($attrs.pageLabel, {$page: idx}); } : function(idx) { return idx; }; $scope.boundaryLinks = angular.isDefined($attrs.boundaryLinks) ? $scope.$parent.$eval($attrs.boundaryLinks) : uibPaginationConfig.boundaryLinks; $scope.directionLinks = angular.isDefined($attrs.directionLinks) ? $scope.$parent.$eval($attrs.directionLinks) : uibPaginationConfig.directionLinks; @@ -57,7 +58,7 @@ angular.module('ui.bootstrap.pagination', ['ui.bootstrap.paging']) // Add page number links for (var number = startPage; number <= endPage; number++) { - var page = makePage(number, number, number === currentPage); + var page = makePage(number, pageLabel(number), number === currentPage); pages.push(page); } diff --git a/src/pagination/test/pagination.spec.js b/src/pagination/test/pagination.spec.js index fb1c82268f..7afa7f4ef2 100644 --- a/src/pagination/test/pagination.spec.js +++ b/src/pagination/test/pagination.spec.js @@ -876,7 +876,10 @@ describe('pagination directive', function() { describe('override configuration from attributes', function() { beforeEach(function() { - element = $compile('')($rootScope); + $rootScope.pageLabel = function(id) { + return 'test_'+ id; + }; + element = $compile('')($rootScope); $rootScope.$digest(); }); @@ -890,6 +893,13 @@ describe('pagination directive', function() { expect(getPaginationEl(-2).text()).toBe('>'); expect(getPaginationEl(-1).text()).toBe('>>'); }); + + it('has the label of the page as text in each page item', function() { + for (var i = 1; i <= 5; i++) { + // +1 because the first element is a < + expect(getPaginationEl(i+1).text()).toEqual('test_'+i); + } + }); }); describe('disabled with ngDisable', function() { From f25a0d32a2023e2525273d8fed30da20c5f957a2 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Fri, 26 Feb 2016 09:51:33 +0000 Subject: [PATCH 2/2] docs(pagination): add 'pageLabel' option --- src/pagination/docs/readme.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pagination/docs/readme.md b/src/pagination/docs/readme.md index c48271a5f6..8cfb7bf2d9 100644 --- a/src/pagination/docs/readme.md +++ b/src/pagination/docs/readme.md @@ -18,7 +18,7 @@ A lightweight pagination directive that is focused on ... providing pagination & C _(Default: `true`)_ - Whether to display Previous / Next buttons. - + * `first-text` C _(Default: `First`)_ - @@ -41,13 +41,13 @@ A lightweight pagination directive that is focused on ... providing pagination & C _(Default: `Last`)_ - Text for Last button. - + * `max-size` $ _(Default: `null`)_ - Limit number for pagination size. - + * `next-text` C _(Default: `Next`)_ - @@ -56,7 +56,7 @@ A lightweight pagination directive that is focused on ... providing pagination & * `ng-change` $ - This can be used to call a function whenever the page changes. - + * `ng-disabled` $ @@ -88,8 +88,11 @@ A lightweight pagination directive that is focused on ... providing pagination & * `template-url` _(Default: `uib/template/pagination/pagination.html`)_ - Override the template for the component with a custom provided template - + * `total-items` $ - Total number of items in all pages. + +* `page-label`- + An optional expression to override the page label based on passing the current page indexes.