Skip to content

Commit 9dc69f0

Browse files
committed
Fix angular-ui#2134 Horizontal scroll bar covers up last row.
now WHEN_NEEDED really acts like ALWAYS when the scrollbar is shown. So the viewport is different, and the sudden scrollbar widths and heights are set and used in calculations for the various widths and heights
1 parent f113977 commit 9dc69f0

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

src/js/core/directives/ui-grid-native-scrollbar.js

+43-7
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,27 @@
3737
var elmMaxScroll = 0;
3838

3939
if ($scope.type === 'vertical') {
40-
// Update the width based on native scrollbar width
41-
$elm.css('width', scrollBarWidth + 'px');
42-
4340
$elm.addClass('vertical');
4441

4542
grid.verticalScrollbarWidth = grid.options.enableVerticalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED ? 0 : scrollBarWidth;
4643
colContainer.verticalScrollbarWidth = grid.verticalScrollbarWidth;
4744

45+
// Update the width based on native scrollbar width
46+
$elm.css('width', grid.verticalScrollbarWidth + 'px');
47+
4848
// Save the initial scroll position for use in scroll events
4949
previousScrollPosition = $elm[0].scrollTop;
5050
}
5151
else if ($scope.type === 'horizontal') {
52-
// Update the height based on native scrollbar height
53-
$elm.css('height', scrollBarWidth + 'px');
54-
5552
$elm.addClass('horizontal');
5653

5754
// Save this scrollbar's dimension in the grid properties
5855
grid.horizontalScrollbarHeight = grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED ? 0 : scrollBarWidth;
5956
rowContainer.horizontalScrollbarHeight = grid.horizontalScrollbarHeight;
6057

58+
// Update the height based on native scrollbar height
59+
$elm.css('height', grid.horizontalScrollbarHeight + 'px');
60+
6161
// Save the initial scroll position for use in scroll events
6262
previousScrollPosition = gridUtil.normalizeScrollLeft($elm);
6363
}
@@ -79,7 +79,26 @@
7979

8080
// Update the vertical scrollbar's content height so it's the same as the canvas
8181
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+
}
83102
//var headerHeight = gridUtil.outerElementHeight(containerCtrl.header);
84103
var headerHeight = colContainer.headerHeight ? colContainer.headerHeight : grid.headerHeight;
85104

@@ -107,9 +126,26 @@
107126
bottom -= 1;
108127
}
109128

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+
}
110143
var adjustment = colContainer.getViewportAdjustment();
111144
bottom -= adjustment.height;
112145

146+
// the vieport is the size minus the scrollbar height, so place it now just below it.
147+
bottom -= rowContainer.horizontalScrollbarHeight;
148+
113149
var ondemand = grid.options.enableHorizontalScrollbar === uiGridConstants.scrollbars.WHEN_NEEDED ? "overflow-x:auto" : "";
114150
var ret = '.grid' + grid.id + ' .ui-grid-render-container-' + containerCtrl.containerId + ' .ui-grid-native-scrollbar.horizontal { bottom: ' + bottom + 'px;' +ondemand + ' }';
115151
ret += '.grid' + grid.id + ' .ui-grid-render-container-' + containerCtrl.containerId + ' .ui-grid-native-scrollbar.horizontal .contents { width: ' + w + 'px; }';

0 commit comments

Comments
 (0)