Skip to content

Commit e137e6b

Browse files
JSlainmportuga
authored andcommitted
fix(#4330): Listen to UPDATE_EVENT and refresh labels for pagination (#6308)
* Issue #4330: Listen to UPDATE_EVENT and refresh labels for pagination * Issue #4330: Forgot to put something back before pushing
1 parent 6cf44b4 commit e137e6b

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

misc/site/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ <h4 class="feature-heading">Basic Example</h4>
159159
<div class="grid" ui-grid="gridOptionsSimple"></div>
160160

161161
<h4 class="feature-heading">Complex Example</h4>
162-
<div class="grid" ui-grid="gridOptionsComplex" ui-grid-edit ui-grid-resize-columns></div>
163-
164-
162+
<div class="grid" ui-grid="gridOptionsComplex" ui-grid-edit ui-grid-resize-columns ui-grid-pagination></div>
165163
<label>Language: </label>
166164
<select ng-options="language for language in languages" ng-model="currentLanguage" ng-change="changeLanguage()"></select>
167165
</div>
@@ -188,7 +186,7 @@ <h4 class="feature-heading">Complex Example</h4>
188186
<script src="//ajax.googleapis.com/ajax/libs/angularjs/<%= latestAngular %>/angular-animate.js"></script>
189187
<script src="//ui-grid.info/release/ui-grid-unstable.min.js"></script>
190188
<script>
191-
angular.module('demo', ['ngAnimate', 'ui.grid', 'ui.grid.edit', 'ui.grid.resizeColumns'])
189+
angular.module('demo', ['ngAnimate', 'ui.grid', 'ui.grid.edit', 'ui.grid.resizeColumns', 'ui.grid.pagination'])
192190
.run(function($rootScope, uiGridConstants, i18nService) {
193191
$rootScope.gridOptionsSimple = {
194192
data: [
@@ -299,6 +297,8 @@ <h4 class="feature-heading">Complex Example</h4>
299297
enableFiltering: true,
300298
showGridFooter: true,
301299
showColumnFooter: true,
300+
paginationPageSizes: [10, 20, 30],
301+
paginationPageSize: 10,
302302
columnDefs: [
303303
{ name: 'name', aggregationType: uiGridConstants.aggregationTypes.count, width: 150 },
304304
{ name: 'gender', filter: { term: 'male' }, width: 150, enableCellEdit: false,

src/features/pagination/js/pagination.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@
378378
*
379379
* @description Panel for handling pagination
380380
*/
381-
module.directive('uiGridPager', ['uiGridPaginationService', 'uiGridConstants', 'gridUtil', 'i18nService',
382-
function (uiGridPaginationService, uiGridConstants, gridUtil, i18nService) {
381+
module.directive('uiGridPager', ['uiGridPaginationService', 'uiGridConstants', 'gridUtil', 'i18nService', 'i18nConstants',
382+
function (uiGridPaginationService, uiGridConstants, gridUtil, i18nService, i18nConstants) {
383383
return {
384384
priority: -200,
385385
scope: true,
@@ -388,11 +388,18 @@
388388
var defaultFocusElementSelector = '.ui-grid-pager-control-input';
389389
$scope.aria = i18nService.getSafeText('pagination.aria'); //Returns an object with all of the aria labels
390390

391-
$scope.paginationApi = uiGridCtrl.grid.api.pagination;
392-
$scope.sizesLabel = i18nService.getSafeText('pagination.sizes');
393-
$scope.totalItemsLabel = i18nService.getSafeText('pagination.totalItems');
394-
$scope.paginationOf = i18nService.getSafeText('pagination.of');
395-
$scope.paginationThrough = i18nService.getSafeText('pagination.through');
391+
var updateLabels = function(){
392+
$scope.paginationApi = uiGridCtrl.grid.api.pagination;
393+
$scope.sizesLabel = i18nService.getSafeText('pagination.sizes');
394+
$scope.totalItemsLabel = i18nService.getSafeText('pagination.totalItems');
395+
$scope.paginationOf = i18nService.getSafeText('pagination.of');
396+
$scope.paginationThrough = i18nService.getSafeText('pagination.through');
397+
};
398+
399+
400+
updateLabels();
401+
402+
$scope.$on(i18nConstants.UPDATE_EVENT, updateLabels);
396403

397404
var options = uiGridCtrl.grid.options;
398405

src/features/pagination/test/pagination.spec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ describe('ui.grid.pagination uiGridPaginationService', function () {
55
var gridElement;
66
var $rootScope;
77
var $timeout;
8+
var i18nService;
89

910
beforeEach(module('ui.grid'));
1011
beforeEach(module('ui.grid.pagination'));
1112

12-
beforeEach(inject(function (_$rootScope_, _$timeout_, $compile) {
13+
beforeEach(inject(function (_$rootScope_, _$timeout_, $compile, _i18nService_) {
1314
$rootScope = _$rootScope_;
1415
$timeout = _$timeout_;
16+
i18nService = _i18nService_;
1517

1618
$rootScope.gridOptions = {
1719
columnDefs: [
@@ -175,6 +177,19 @@ describe('ui.grid.pagination uiGridPaginationService', function () {
175177
expect(gridRows.eq(0).find('div.ui-grid-cell').eq(1).text()).toBe('K');
176178
});
177179
});
180+
181+
it('changes labels according to i18nService', function(){
182+
$rootScope.$digest();
183+
$timeout.flush();
184+
185+
expect(gridElement.find('.ui-grid-pager-row-count-label').text()).toEqual(' items per page');
186+
187+
i18nService.setCurrentLang('fr');
188+
189+
$rootScope.$digest();
190+
191+
expect(gridElement.find('.ui-grid-pager-row-count-label').text()).toEqual(' éléments par page');
192+
});
178193
});
179194

180195
describe('custom pagination', function () {

src/js/i18n/ui-i18n.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
* @name setCurrentLang
185185
* @methodOf ui.grid.i18n.service:i18nService
186186
* @description sets the current language to use in the application
187-
* $broadcasts the Update_Event on the $rootScope
187+
* $broadcasts the i18nConstants.UPDATE_EVENT on the $rootScope
188188
* @param {string} lang to set
189189
* @example
190190
* <pre>

0 commit comments

Comments
 (0)