From 365f21f0bb8383c2103af0dea6e3a03986db0c04 Mon Sep 17 00:00:00 2001 From: swalters Date: Wed, 3 Jun 2015 15:42:04 -0500 Subject: [PATCH] fix(core): add a horizontal scrollbar placeholder when needed --- .../directives/ui-grid-render-container.js | 10 ++-- src/js/core/directives/ui-pinned-container.js | 4 +- src/js/core/factories/GridRenderContainer.js | 49 +++++++++++++------ src/less/grid.less | 4 ++ .../ui-grid/uiGridRenderContainer.html | 1 + src/templates/ui-grid/uiGridViewport.html | 2 +- 6 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/js/core/directives/ui-grid-render-container.js b/src/js/core/directives/ui-grid-render-container.js index 94db9db0c9..15cb30b951 100644 --- a/src/js/core/directives/ui-grid-render-container.js +++ b/src/js/core/directives/ui-grid-render-container.js @@ -129,11 +129,15 @@ var canvasHeight = rowContainer.getCanvasHeight(); //add additional height for scrollbar on left and right container - if ($scope.containerId !== 'body') { - canvasHeight += grid.scrollbarHeight; - } + //if ($scope.containerId !== 'body') { + // canvasHeight -= grid.scrollbarHeight; + //} var viewportHeight = rowContainer.getViewportHeight(); + //shorten the height to make room for a scrollbar placeholder + if (colContainer.needsHScrollbarPlaceholder()) { + viewportHeight -= grid.scrollbarHeight; + } var headerViewportWidth, footerViewportWidth; diff --git a/src/js/core/directives/ui-pinned-container.js b/src/js/core/directives/ui-pinned-container.js index f500791911..307bfb97ef 100644 --- a/src/js/core/directives/ui-pinned-container.js +++ b/src/js/core/directives/ui-pinned-container.js @@ -69,9 +69,9 @@ // TODO(c0bra): Subtract sum of col widths from grid viewport width and update it $elm.attr('style', null); - var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight; + // var myHeight = grid.renderContainers.body.getViewportHeight(); // + grid.horizontalScrollbarHeight; - 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; } '; + 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; } '; } return ret; diff --git a/src/js/core/factories/GridRenderContainer.js b/src/js/core/factories/GridRenderContainer.js index ed7ae2791e..a171d3ba72 100644 --- a/src/js/core/factories/GridRenderContainer.js +++ b/src/js/core/factories/GridRenderContainer.js @@ -45,6 +45,22 @@ angular.module('ui.grid') self.viewportAdjusters = []; + /** + * @ngdoc boolean + * @name hasHScrollbar + * @propertyOf ui.grid.class:GridRenderContainer + * @description flag to signal that container has a horizontal scrollbar + */ + self.hasHScrollbar = false; + + /** + * @ngdoc boolean + * @name hasHScrollbar + * @propertyOf ui.grid.class:GridRenderContainer + * @description flag to signal that container has a vertical scrollbar + */ + self.hasVScrollbar = false; + /** * @ngdoc boolean * @name canvasHeightShouldUpdate @@ -715,9 +731,16 @@ angular.module('ui.grid') this.columnStyles = ret; }; + GridRenderContainer.prototype.needsHScrollbarPlaceholder = function () { + return this.grid.options.enableHorizontalScrollbar && !this.hasHScrollbar; + }; + GridRenderContainer.prototype.getViewportStyle = function () { var self = this; var styles = {}; + + self.hasHScrollbar = false; + self.hasVScrollbar = false; if (self.grid.disableScrolling) { styles['overflow-x'] = 'hidden'; @@ -726,33 +749,29 @@ angular.module('ui.grid') } if (self.name === 'body') { - styles['overflow-x'] = self.grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll'; + self.hasHScrollbar = self.grid.options.enableHorizontalScrollbar !== uiGridConstants.scrollbars.NEVER; if (!self.grid.isRTL()) { - if (self.grid.hasRightContainerColumns()) { - styles['overflow-y'] = 'hidden'; - } - else { - styles['overflow-y'] = self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll'; + if (!self.grid.hasRightContainerColumns()) { + self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER; } } else { - if (self.grid.hasLeftContainerColumns()) { - styles['overflow-y'] = 'hidden'; - } - else { - styles['overflow-y'] = self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll'; + if (!self.grid.hasLeftContainerColumns()) { + self.hasVScrollbar = self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER; } } } else if (self.name === 'left') { - styles['overflow-x'] = 'hidden'; - styles['overflow-y'] = self.grid.isRTL() ? (self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll') : 'hidden'; + self.hasVScrollbar = self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false; } else { - styles['overflow-x'] = 'hidden'; - styles['overflow-y'] = !self.grid.isRTL() ? (self.grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.NEVER ? 'hidden' : 'scroll') : 'hidden'; + self.hasVScrollbar = !self.grid.isRTL() ? self.grid.options.enableVerticalScrollbar !== uiGridConstants.scrollbars.NEVER : false; } + styles['overflow-x'] = self.hasHScrollbar ? 'scroll' : 'hidden'; + styles['overflow-y'] = self.hasVScrollbar ? 'scroll' : 'hidden'; + + return styles; diff --git a/src/less/grid.less b/src/less/grid.less index 991890b5c9..671bce9ad6 100644 --- a/src/less/grid.less +++ b/src/less/grid.less @@ -19,6 +19,10 @@ width: @gridBorderWidth; } +.ui-grid-scrollbar-placeholder{ + background-color: @headerVerticalBarColor; +} + .ui-grid-header-cell:not(:last-child) .ui-grid-vertical-bar { background-color: @headerVerticalBarColor; } diff --git a/src/templates/ui-grid/uiGridRenderContainer.html b/src/templates/ui-grid/uiGridRenderContainer.html index 578ffd629d..179943f326 100644 --- a/src/templates/ui-grid/uiGridRenderContainer.html +++ b/src/templates/ui-grid/uiGridRenderContainer.html @@ -1,5 +1,6 @@
+
diff --git a/src/templates/ui-grid/uiGridViewport.html b/src/templates/ui-grid/uiGridViewport.html index 16f8946366..7926aee3bd 100644 --- a/src/templates/ui-grid/uiGridViewport.html +++ b/src/templates/ui-grid/uiGridViewport.html @@ -4,4 +4,4 @@
- \ No newline at end of file +