Skip to content

Commit 365f21f

Browse files
committed
fix(core): add a horizontal scrollbar placeholder when needed
1 parent 6514709 commit 365f21f

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

src/js/core/directives/ui-grid-render-container.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,15 @@
129129
var canvasHeight = rowContainer.getCanvasHeight();
130130

131131
//add additional height for scrollbar on left and right container
132-
if ($scope.containerId !== 'body') {
133-
canvasHeight += grid.scrollbarHeight;
134-
}
132+
//if ($scope.containerId !== 'body') {
133+
// canvasHeight -= grid.scrollbarHeight;
134+
//}
135135

136136
var viewportHeight = rowContainer.getViewportHeight();
137+
//shorten the height to make room for a scrollbar placeholder
138+
if (colContainer.needsHScrollbarPlaceholder()) {
139+
viewportHeight -= grid.scrollbarHeight;
140+
}
137141

138142
var headerViewportWidth,
139143
footerViewportWidth;

src/js/core/directives/ui-pinned-container.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
// TODO(c0bra): Subtract sum of col widths from grid viewport width and update it
7070
$elm.attr('style', null);
7171

72-
var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight;
72+
// var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight;
7373

74-
ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; height: ' + myHeight + 'px; } ';
74+
ret += '.grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ', .grid' + grid.id + ' .ui-grid-pinned-container-' + $scope.side + ' .ui-grid-render-container-' + $scope.side + ' .ui-grid-viewport { width: ' + myWidth + 'px; } ';
7575
}
7676

7777
return ret;

src/js/core/factories/GridRenderContainer.js

+34-15
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ angular.module('ui.grid')
4545

4646
self.viewportAdjusters = [];
4747

48+
/**
49+
* @ngdoc boolean
50+
* @name hasHScrollbar
51+
* @propertyOf ui.grid.class:GridRenderContainer
52+
* @description flag to signal that container has a horizontal scrollbar
53+
*/
54+
self.hasHScrollbar = false;
55+
56+
/**
57+
* @ngdoc boolean
58+
* @name hasHScrollbar
59+
* @propertyOf ui.grid.class:GridRenderContainer
60+
* @description flag to signal that container has a vertical scrollbar
61+
*/
62+
self.hasVScrollbar = false;
63+
4864
/**
4965
* @ngdoc boolean
5066
* @name canvasHeightShouldUpdate
@@ -715,9 +731,16 @@ angular.module('ui.grid')
715731
this.columnStyles = ret;
716732
};
717733

734+
GridRenderContainer.prototype.needsHScrollbarPlaceholder = function () {
735+
return this.grid.options.enableHorizontalScrollbar && !this.hasHScrollbar;
736+
};
737+
718738
GridRenderContainer.prototype.getViewportStyle = function () {
719739
var self = this;
720740
var styles = {};
741+
742+
self.hasHScrollbar = false;
743+
self.hasVScrollbar = false;
721744

722745
if (self.grid.disableScrolling) {
723746
styles['overflow-x'] = 'hidden';
@@ -726,33 +749,29 @@ angular.module('ui.grid')
726749
}
727750

728751
if (self.name === 'body') {
729-
styles['overflow-x'] = self.grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll';
752+
self.hasHScrollbar = self.grid.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER;
730753
if (!self.grid.isRTL()) {
731-
if (self.grid.hasRightContainerColumns()) {
732-
styles['overflow-y'] = 'hidden';
733-
}
734-
else {
735-
styles['overflow-y'] = self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll';
754+
if (!self.grid.hasRightContainerColumns()) {
755+
self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
736756
}
737757
}
738758
else {
739-
if (self.grid.hasLeftContainerColumns()) {
740-
styles['overflow-y'] = 'hidden';
741-
}
742-
else {
743-
styles['overflow-y'] = self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll';
759+
if (!self.grid.hasLeftContainerColumns()) {
760+
self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER;
744761
}
745762
}
746763
}
747764
else if (self.name === 'left') {
748-
styles['overflow-x'] = 'hidden';
749-
styles['overflow-y'] = self.grid.isRTL() ? (self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll') : 'hidden';
765+
self.hasVScrollbar = self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
750766
}
751767
else {
752-
styles['overflow-x'] = 'hidden';
753-
styles['overflow-y'] = !self.grid.isRTL() ? (self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll') : 'hidden';
768+
self.hasVScrollbar = !self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false;
754769
}
755770

771+
styles['overflow-x'] = self.hasHScrollbar ? 'scroll' : 'hidden';
772+
styles['overflow-y'] = self.hasVScrollbar ? 'scroll' : 'hidden';
773+
774+
756775
return styles;
757776

758777

src/less/grid.less

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
width: @gridBorderWidth;
2020
}
2121

22+
.ui-grid-scrollbar-placeholder{
23+
background-color: @headerVerticalBarColor;
24+
}
25+
2226
.ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar {
2327
background-color: @headerVerticalBarColor;
2428
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="ui-grid-render-container" ng-style="{ 'margin-left': colContainer.getMargin('left') + 'px', 'margin-right': colContainer.getMargin('right') + 'px' }">
22
<div ui-grid-header></div>
33
<div ui-grid-viewport></div>
4+
<div ng-if="colContainer.needsHScrollbarPlaceholder()" class="ui-grid-scrollbar-placeholder" style="height:{{colContainer.grid.scrollbarHeight}}px"></div>
45
<div ui-grid-footer ng-if="grid.options.showColumnFooter"></div>
56
</div>

src/templates/ui-grid/uiGridViewport.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
<div ui-grid-row="row" row-render-index="rowRenderIndex"></div>
55
</div>
66
</div>
7-
</div>
7+
</div>

0 commit comments

Comments
 (0)