Skip to content

Commit

Permalink
fix(Grid.js) Vertical scroll calculates height wrong with enableHoriz…
Browse files Browse the repository at this point in the history
…ontalScrollbar: NEVER (angular-ui#6690)

* fix(Grid.js): ScrollIfNecessary does not account for scrollWidth correctly

Since scrollIfNecessary is called multiple times when enableCellEditOnFocus is true we need to make sure the scrollbarWidth and footerHeight is accounted for to not cause a loop.

fixes angular-ui#6653

* Add check for gridCol not null

Make sure gridCol is not null before checking for enableCellEditOnFocus

* fix(Grid.js) Vertical scroll calculates height wrong with enableHorizontalScrollbar: NEVER

Use scrollbarHeight instead of scrollbarWidth for vertical scroll calculations. scrollbarHeight has the value 0 when enableHorizontalScrollbar is set to NEVER.

Round calculated boundary values as computed style may have decimal number which will not match pixelsToSeeRow
  • Loading branch information
m4m4m4 authored and Devin Fields committed Oct 30, 2018
1 parent 5b8a243 commit 0c1cbde
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2402,7 +2402,7 @@ angular.module('ui.grid')

// The bottom boundary is the current Y scroll position, plus the height of the grid, but minus the header height.
// Basically this is the viewport height added on to the scroll position
var bottomBound = self.renderContainers.body.prevScrollTop + self.gridHeight - self.renderContainers.body.headerHeight - self.footerHeight - self.scrollbarWidth;
var bottomBound = self.renderContainers.body.prevScrollTop + self.gridHeight - self.renderContainers.body.headerHeight - self.footerHeight - self.scrollbarHeight;

// If there's a horizontal scrollbar, remove its height from the bottom boundary, otherwise we'll be letting it obscure rows
//if (self.horizontalScrollbarHeight) {
Expand Down Expand Up @@ -2439,20 +2439,20 @@ angular.module('ui.grid')
var scrollPixels;

// If the scroll position we need to see the row is LESS than the top boundary, i.e. obscured above the top of the self...
if (pixelsToSeeRow < topBound) {
if (pixelsToSeeRow < Math.floor(topBound)) {
// Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
// to get the full position we need
scrollPixels = self.renderContainers.body.prevScrollTop - (topBound - pixelsToSeeRow);

//Since scrollIfNecessary is called multiple times when enableCellEditOnFocus is true we need to make sure the scrollbarWidth and footerHeight is accounted for to not cause a loop.
if (gridCol && gridCol.colDef && gridCol.colDef.enableCellEditOnFocus) {
scrollPixels = scrollPixels - self.footerHeight - self.scrollbarWidth;
scrollPixels = scrollPixels - self.footerHeight - self.scrollbarHeight;
}

scrollEvent.y = getScrollY(scrollPixels, scrollLength, self.renderContainers.body.prevScrolltopPercentage);
}
// Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
else if (pixelsToSeeRow > bottomBound) {
else if (pixelsToSeeRow > Math.ceil(bottomBound)) {
// Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
// to get the full position we need
scrollPixels = pixelsToSeeRow - bottomBound + self.renderContainers.body.prevScrollTop;
Expand Down

0 comments on commit 0c1cbde

Please sign in to comment.