Skip to content

Commit cf86090

Browse files
committed
fix(Grid): Adjust available width for columns
With the newer native scrollbar changes we need to subtract the scrollbar width from the available width used to render the columns, otherwise the viewport contents will overflow the visible area and cause the viewport to scroll horizontally when we don't want it to. Thanks to @dczepierga for tracking down the cause and solution. Fixes #2521, #2734, #2592
1 parent e099c5b commit cf86090

File tree

7 files changed

+26
-6
lines changed

7 files changed

+26
-6
lines changed

Diff for: src/features/resize-columns/less/column-resizer.less

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
}
1717
}
1818

19+
// Add a visual border for final column's resizer element
20+
.ui-grid-header-cell:last-child .ui-grid-column-resizer.right {
21+
border-right: @gridBorderWidth solid @borderColor;
22+
}
23+
24+
// Put visual border on left of last header cell when direction is rtl
25+
.ui-grid[dir=rtl] .ui-grid-header-cell:last-child {
26+
.ui-grid-column-resizer.right {
27+
border-right: 0;
28+
}
29+
30+
.ui-grid-column-resizer.left {
31+
border-left: @gridBorderWidth solid @borderColor;
32+
}
33+
}
34+
1935
.ui-grid {
2036
&.column-resizing {
2137
cursor: col-resize;

Diff for: src/js/core/directives/ui-grid-header.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272

7373
function updateColumnWidths() {
7474
// Get the width of the viewport
75-
var availableWidth = containerCtrl.colContainer.getViewportWidth();
75+
var availableWidth = containerCtrl.colContainer.getViewportWidth() - grid.scrollbarWidth;
7676

7777
//if (typeof(uiGridCtrl.grid.verticalScrollbarWidth) !== 'undefined' && uiGridCtrl.grid.verticalScrollbarWidth !== undefined && uiGridCtrl.grid.verticalScrollbarWidth > 0) {
7878
// availableWidth = availableWidth + uiGridCtrl.grid.verticalScrollbarWidth;

Diff for: src/js/core/factories/GridRenderContainer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ angular.module('ui.grid')
545545
totalWidth = 0;
546546

547547
// Get the width of the viewport
548-
var availableWidth = self.getViewportWidth();
548+
var availableWidth = self.getViewportWidth() - self.grid.scrollbarWidth;
549549

550550
//if (typeof(self.grid.verticalScrollbarWidth) !== 'undefined' && self.grid.verticalScrollbarWidth !== undefined && self.grid.verticalScrollbarWidth > 0) {
551551
// availableWidth = availableWidth + self.grid.verticalScrollbarWidth;

Diff for: src/less/cell.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
box-sizing: border-box;
1212

1313
&:last-child {
14-
// border-right: 0;
14+
border-right: 0;
1515
}
1616
}
1717

Diff for: src/less/header.less

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
border-right: @gridBorderWidth solid;
5656
border-color: @headerVerticalBarColor;
5757

58+
&:last-child {
59+
border-right: 0;
60+
}
61+
5862
.user-select(none);
5963

6064
// Default to width 0 so header height can calculate right. Otherwise

Diff for: src/less/rtl.less

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
}
2525

2626
.ui-grid-cell:last-child, .ui-grid-header-cell:last-child {
27-
border-left: @gridBorderWidth solid;
28-
border-color: @borderColor;
27+
border-right: @gridBorderWidth solid @borderColor;
28+
border-left: 0;
2929
}
3030

3131
.ui-grid-header-cell:first-child .ui-grid-vertical-bar,

Diff for: test/unit/core/directives/ui-grid.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('ui-grid', function() {
118118
renderWidth += c.drawnWidth;
119119
});
120120

121-
expect(renderWidth).toBe(gridApi.grid.gridWidth);
121+
expect(renderWidth).toBe(gridApi.grid.getViewportWidth() - gridApi.grid.scrollbarWidth);
122122
});
123123
});
124124

0 commit comments

Comments
 (0)