Skip to content

Commit 403bf3e

Browse files
Ditommaso, Danielmportuga
Ditommaso, Daniel
authored andcommitted
fix(GridRenderContainer.js): needsHScrollbarPlaceholder accounts for WHEN_NEEDED
Added logic to needsHScrollbarPlaceholder to account for left/right rendercontainers as well as handle case when gridOption enableHorizontalScrollbar is set to WHEN_NEEDED. fix #6280, fix #5812, fix #5760, fix #6590, fix #6572, fix #6528, fix #4251, fix #3022
1 parent 9ebe116 commit 403bf3e

File tree

4 files changed

+97
-11
lines changed

4 files changed

+97
-11
lines changed

src/js/core/factories/Grid.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ angular.module('ui.grid')
190190

191191
self.scrollbarHeight = 0;
192192
self.scrollbarWidth = 0;
193-
if (self.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
193+
if (self.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER) {
194194
self.scrollbarHeight = gridUtil.getScrollbarWidth();
195195
}
196196

197-
if (self.options.enableVerticalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
197+
if (self.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER) {
198198
self.scrollbarWidth = gridUtil.getScrollbarWidth();
199199
}
200200

src/js/core/factories/GridRenderContainer.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,17 @@ angular.module('ui.grid')
764764
};
765765

766766
GridRenderContainer.prototype.needsHScrollbarPlaceholder = function () {
767-
return this.grid.options.enableHorizontalScrollbar && !this.hasHScrollbar && !this.grid.disableScrolling;
767+
var self = this,
768+
containerBody;
769+
770+
if (self.name === 'left' || self.name === 'right' && !this.hasHScrollbar && !this.grid.disableScrolling) {
771+
if (self.grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.ALWAYS) {
772+
return true;
773+
}
774+
containerBody = this.grid.element[0].querySelector('.ui-grid-render-container-body .ui-grid-viewport');
775+
return containerBody.scrollWidth > containerBody.offsetWidth;
776+
}
777+
return false;
768778
};
769779

770780
GridRenderContainer.prototype.getViewportStyle = function () {

test/unit/core/factories/Grid.spec.js

+35-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
describe('Grid factory', function () {
2-
var $timeout, $q, $scope, grid, Grid, GridRow, GridColumn, rows, returnedRows, column, uiGridConstants, gridClassFactory;
2+
var $timeout, $q, $scope, grid, Grid, GridRow, GridColumn, rows, returnedRows, column, uiGridConstants,
3+
gridClassFactory, gridUtil;
34

45
beforeEach(function() {
56
module('ui.grid');
67

7-
inject(function (_$timeout_, _$q_, _$rootScope_, _Grid_, _GridRow_, _GridColumn_, _uiGridConstants_, _gridClassFactory_) {
8+
inject(function (_$timeout_, _$q_, _$rootScope_, _Grid_, _GridRow_, _GridColumn_, _uiGridConstants_,
9+
_gridClassFactory_, _gridUtil_) {
810
$timeout = _$timeout_;
911
$q = _$q_;
1012
$scope = _$rootScope_;
@@ -13,6 +15,7 @@ describe('Grid factory', function () {
1315
GridColumn = _GridColumn_;
1416
uiGridConstants = _uiGridConstants_;
1517
gridClassFactory = _gridClassFactory_;
18+
gridUtil = _gridUtil_;
1619
});
1720
grid = new Grid({ id: 1 });
1821
rows = [
@@ -47,9 +50,9 @@ describe('Grid factory', function () {
4750
var canvasWidth = 100;
4851

4952
beforeEach(function() {
50-
renderContainers = {
51-
body: {
52-
visibleRowCache: null,
53+
renderContainers = {
54+
body: {
55+
visibleRowCache: null,
5356
visibleColumnCache: null,
5457
prevScrollTop: prevScrollTop,
5558
headerHeight: 30,
@@ -99,7 +102,7 @@ describe('Grid factory', function () {
99102
});
100103

101104
$scope.$apply();
102-
});
105+
});
103106
});
104107

105108
describe('constructor', function() {
@@ -123,6 +126,32 @@ describe('Grid factory', function () {
123126
expect(e).toMatch(/It must follow CSS selector syntax rules/);
124127
}
125128
});
129+
describe('scrollbarHeight and scrollbarWidth', function() {
130+
describe('when enableHorizontalScrollbar not equal to NEVER', function() {
131+
it('should set scrollbarHeight and scrollbarWidth', function() {
132+
var grid = new Grid({
133+
id: 1,
134+
enableHorizontalScrollbar: uiGridConstants.scrollbars.ALWAYS,
135+
enableVerticalScrollbar: uiGridConstants.scrollbars.ALWAYS
136+
});
137+
138+
expect(grid.scrollbarHeight).not.toEqual(0);
139+
expect(grid.scrollbarWidth).not.toEqual(0);
140+
});
141+
});
142+
describe('when enableHorizontalScrollbar is equal to NEVER', function() {
143+
it('should set scrollbarHeight and scrollbarWidth to 0', function() {
144+
var grid = new Grid({
145+
id: 1,
146+
enableHorizontalScrollbar: uiGridConstants.scrollbars.NEVER,
147+
enableVerticalScrollbar: uiGridConstants.scrollbars.NEVER
148+
});
149+
150+
expect(grid.scrollbarHeight).toEqual(0);
151+
expect(grid.scrollbarWidth).toEqual(0);
152+
});
153+
});
154+
});
126155
});
127156

128157
describe('row processors', function () {
@@ -278,8 +307,6 @@ describe('Grid factory', function () {
278307

279308
});
280309

281-
282-
283310
describe('buildColumns', function() {
284311
it('guess correct column types when not specified', function() {
285312
var dataRow = {str:'abc', num:123, dat:new Date(), bool:true, obj:{}, nll:null, negNum:-1, posNum:+1 };

test/unit/core/factories/GridRenderContainer.spec.js

+49
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,55 @@ describe('GridRenderContainer factory', function() {
106106

107107
});
108108

109+
describe('needsHScrollbarPlaceholder', function() {
110+
var r;
111+
112+
function initializeRenderContainer(scrollbarSetting, scrollWidth, offsetWidth) {
113+
grid.element = [{
114+
querySelector: function() {
115+
return {
116+
scrollWidth: scrollWidth,
117+
offsetWidth: offsetWidth
118+
};
119+
}
120+
}];
121+
grid.options.enableHorizontalScrollbar = scrollbarSetting;
122+
r = new GridRenderContainer('name', grid);
123+
}
124+
describe('body render container', function() {
125+
it('should return false', function() {
126+
initializeRenderContainer();
127+
r.name = 'body';
128+
expect(r.needsHScrollbarPlaceholder()).toEqual(false);
129+
});
130+
});
131+
132+
describe('left && right render containers', function() {
133+
describe('grid options enableHorizontalScrollbar === ALWAYS', function() {
134+
it('should return true', function() {
135+
initializeRenderContainer(uiGridConstants.scrollbars.ALWAYS);
136+
r.name = 'left';
137+
expect(r.needsHScrollbarPlaceholder()).toEqual(true);
138+
139+
r.name = 'right';
140+
expect(r.needsHScrollbarPlaceholder()).toEqual(true);
141+
});
142+
});
143+
describe('grid options enableHorizontalScrollbar === WHEN_NEEDED', function() {
144+
it('should return true if body render container is scrollable', function () {
145+
initializeRenderContainer(uiGridConstants.scrollbars.WHEN_NEEDED, 100, 50);
146+
r.name = 'left';
147+
expect(r.needsHScrollbarPlaceholder()).toBe(true);
148+
});
149+
it('should return false if body render container is not scrollable', function () {
150+
initializeRenderContainer(uiGridConstants.scrollbars.WHEN_NEEDED, 50, 100);
151+
r.name = 'left';
152+
expect(r.needsHScrollbarPlaceholder()).toBe(false);
153+
});
154+
});
155+
});
156+
});
157+
109158
describe('updateWidths', function() {
110159
beforeEach(function() {
111160
grid.buildColumns();

0 commit comments

Comments
 (0)