|
37 | 37 | var elmMaxScroll = 0;
|
38 | 38 |
|
39 | 39 | if ($scope.type === 'vertical') {
|
40 |
| - // Update the width based on native scrollbar width |
41 |
| - $elm.css('width', scrollBarWidth + 'px'); |
42 |
| - |
43 | 40 | $elm.addClass('vertical');
|
44 | 41 |
|
45 | 42 | grid.verticalScrollbarWidth = grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED ? 0 : scrollBarWidth;
|
46 | 43 | colContainer.verticalScrollbarWidth = grid.verticalScrollbarWidth;
|
47 | 44 |
|
| 45 | + // Update the width based on native scrollbar width |
| 46 | + $elm.css('width', grid.verticalScrollbarWidth + 'px'); |
| 47 | + |
48 | 48 | // Save the initial scroll position for use in scroll events
|
49 | 49 | previousScrollPosition = $elm[0].scrollTop;
|
50 | 50 | }
|
51 | 51 | else if ($scope.type === 'horizontal') {
|
52 |
| - // Update the height based on native scrollbar height |
53 |
| - $elm.css('height', scrollBarWidth + 'px'); |
54 |
| - |
55 | 52 | $elm.addClass('horizontal');
|
56 | 53 |
|
57 | 54 | // Save this scrollbar's dimension in the grid properties
|
58 | 55 | grid.horizontalScrollbarHeight = grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED ? 0 : scrollBarWidth;
|
59 | 56 | rowContainer.horizontalScrollbarHeight = grid.horizontalScrollbarHeight;
|
60 | 57 |
|
| 58 | + // Update the height based on native scrollbar height |
| 59 | + $elm.css('height', grid.horizontalScrollbarHeight + 'px'); |
| 60 | + |
61 | 61 | // Save the initial scroll position for use in scroll events
|
62 | 62 | previousScrollPosition = gridUtil.normalizeScrollLeft($elm);
|
63 | 63 | }
|
|
79 | 79 |
|
80 | 80 | // Update the vertical scrollbar's content height so it's the same as the canvas
|
81 | 81 | var contentHeight = rowContainer.getCanvasHeight();
|
82 |
| - |
| 82 | + |
| 83 | + if (grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED) { |
| 84 | + if (grid.verticalScrollbarWidth === 0 && contentHeight > height) { |
| 85 | + $elm.css('width', scrollBarWidth + 'px'); |
| 86 | + grid.verticalScrollbarWidth = scrollBarWidth; |
| 87 | + colContainer.verticalScrollbarWidth = grid.verticalScrollbarWidth; |
| 88 | + // Add the vertical scrollbar width back in to the canvas width, it's taken out in getCanvasWidth |
| 89 | + colContainer.canvasWidth = colContainer.canvasWidth + colContainer.verticalScrollbarWidth; |
| 90 | + } |
| 91 | + else if (grid.verticalScrollbarWidth > 0 && contentHeight <= height) { |
| 92 | + // remove the vertical scrollbar width from the canvas width, it's taken out in getCanvasWidth |
| 93 | + colContainer.canvasWidth = colContainer.canvasWidth - colContainer.verticalScrollbarWidth; |
| 94 | + $elm.css('width', 0 + 'px'); |
| 95 | + grid.verticalScrollbarWidth = 0; |
| 96 | + colContainer.verticalScrollbarWidth = grid.verticalScrollbarWidth; |
| 97 | + } |
| 98 | + // the height could be adjusted because of the scrollbar that is now visible |
| 99 | + height = rowContainer.getViewportHeight(); |
| 100 | + contentHeight = rowContainer.getCanvasHeight(); |
| 101 | + } |
83 | 102 | //var headerHeight = gridUtil.outerElementHeight(containerCtrl.header);
|
84 | 103 | var headerHeight = colContainer.headerHeight ? colContainer.headerHeight : grid.headerHeight;
|
85 | 104 |
|
|
107 | 126 | bottom -= 1;
|
108 | 127 | }
|
109 | 128 |
|
| 129 | + if (grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED) { |
| 130 | + if (grid.horizontalScrollbarHeight === 0 && w > (colContainer.getViewportWidth() + colContainer.verticalScrollbarWidth)) { |
| 131 | + $elm.css('height', scrollBarWidth + 'px'); |
| 132 | + grid.horizontalScrollbarHeight = scrollBarWidth; |
| 133 | + rowContainer.horizontalScrollbarHeight = grid.horizontalScrollbarHeight; |
| 134 | + } |
| 135 | + else if (grid.horizontalScrollbarHeight > 0 && w <= (colContainer.getViewportWidth() + colContainer.verticalScrollbarWidth)) { |
| 136 | + $elm.css('height', 0 + 'px'); |
| 137 | + grid.horizontalScrollbarHeight = 0; |
| 138 | + rowContainer.horizontalScrollbarHeight = grid.horizontalScrollbarHeight; |
| 139 | + } |
| 140 | + // the widht could be adjusted because of the scrollbar |
| 141 | + w = colContainer.getCanvasWidth(); |
| 142 | + } |
110 | 143 | var adjustment = colContainer.getViewportAdjustment();
|
111 | 144 | bottom -= adjustment.height;
|
112 | 145 |
|
| 146 | + // the vieport is the size minus the scrollbar height, so place it now just below it. |
| 147 | + bottom -= rowContainer.horizontalScrollbarHeight; |
| 148 | + |
113 | 149 | var ondemand = grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED ? "overflow-x:auto" : "";
|
114 | 150 | var ret = '.grid' + grid.id + ' .ui-grid-render-container-' + containerCtrl.containerId + ' .ui-grid-native-scrollbar.horizontal { bottom: ' + bottom + 'px;' +ondemand + ' }';
|
115 | 151 | ret += '.grid' + grid.id + ' .ui-grid-render-container-' + containerCtrl.containerId + ' .ui-grid-native-scrollbar.horizontal .contents { width: ' + w + 'px; }';
|
|
0 commit comments