Skip to content

Commit

Permalink
fix: left frozen section shoudn't go over viewport width, fix #473 (#607
Browse files Browse the repository at this point in the history
)

- fixes #473
- with frozeen grid, we have 2 horizontal scrolling and if any of the column width on the left section goes over the viewport total width then we completely lose the scrolling on the right section (as described in issue #473)
  • Loading branch information
ghiscoding authored May 17, 2021
1 parent 1466b8a commit f229917
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion slick.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ if (typeof Slick === "undefined") {
frozenBottom: false,
frozenColumn: -1,
frozenRow: -1,
frozenRightViewportMinWidth: 100,
fullWidthRows: false,
multiColumnSort: false,
numberedMultiColumnSort: false,
Expand Down Expand Up @@ -1585,6 +1586,7 @@ if (typeof Slick === "undefined") {

function setupColumnResize() {
var $col, j, k, c, pageX, columnElements, minPageX, maxPageX, firstResizable, lastResizable;
var frozenLeftColMaxWidth = 0;
columnElements = $headers.children();
columnElements.find(".slick-resizable-handle").remove();
columnElements.each(function (i, e) {
Expand Down Expand Up @@ -1612,6 +1614,7 @@ if (typeof Slick === "undefined") {
return false;
}
pageX = e.pageX;
frozenLeftColMaxWidth = 0;
$(this).parent().addClass("slick-header-column-active");
var shrinkLeewayOnRight = null, stretchLeewayOnRight = null;
// lock each column's width option to current width
Expand Down Expand Up @@ -1671,6 +1674,7 @@ if (typeof Slick === "undefined") {
columnResizeDragging = true;
var actualMinWidth, d = Math.min(maxPageX, Math.max(minPageX, e.pageX)) - pageX, x;
var newCanvasWidthL = 0, newCanvasWidthR = 0;
var viewportWidth = viewportHasVScroll ? viewportW - scrollbarDimensions.width : viewportW;

if (d < 0) { // shrink column
x = d;
Expand Down Expand Up @@ -1759,7 +1763,18 @@ if (typeof Slick === "undefined") {
x -= c.maxWidth - c.previousWidth;
c.width = c.maxWidth;
} else {
c.width = c.previousWidth + x;
var newWidth = c.previousWidth + x;
var resizedCanvasWidthL = canvasWidthL + x;

if (hasFrozenColumns() && (j <= options.frozenColumn)) {
// if we're on the left frozen side, we need to make sure that our left section width never goes over the total viewport width
if (newWidth > frozenLeftColMaxWidth && resizedCanvasWidthL < (viewportWidth - options.frozenRightViewportMinWidth)) {
frozenLeftColMaxWidth = newWidth; // keep max column width ref, if we go over the limit this number will stop increasing
}
c.width = ((resizedCanvasWidthL + options.frozenRightViewportMinWidth) > viewportWidth) ? frozenLeftColMaxWidth : newWidth;
} else {
c.width = newWidth;
}
x = 0;
}
}
Expand Down

0 comments on commit f229917

Please sign in to comment.