Skip to content

Commit

Permalink
fix column stretching (div and window)
Browse files Browse the repository at this point in the history
  • Loading branch information
warpech committed Jan 9, 2015
1 parent 73ad76b commit 874f892
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
40 changes: 30 additions & 10 deletions src/3rdparty/walkontable/src/viewport.js
Expand Up @@ -23,30 +23,50 @@ WalkontableViewport.prototype.getWorkspaceHeight = function () {
}
};


WalkontableViewport.prototype.getWorkspaceWidth = function () {
var width;

var totalColumns = this.instance.getSetting("totalColumns");
var scrollHandler = this.instance.wtScrollbars.horizontal.scrollHandler;
if (scrollHandler === window) {

if(Handsontable.freezeOverlays) {
width = Math.min(document.documentElement.offsetWidth - this.getWorkspaceOffset().left, document.documentElement.offsetWidth);
} else {
width = Math.min(this.getContainerFillWidth(), document.documentElement.offsetWidth - this.getWorkspaceOffset().left, document.documentElement.offsetWidth);
}

if (scrollHandler === window && totalColumns > 0 && this.sumColumnWidths(0, totalColumns - 1) > width) {
//in case sum of column widths is higher than available stylesheet width, let's assume using the whole window
//otherwise continue below, which will allow stretching
//this is used in `scroll_window.html`
//TODO test me
return document.documentElement.clientWidth;
}
else {
if(Handsontable.freezeOverlays) {
width = Math.min(document.documentElement.offsetWidth - this.getWorkspaceOffset().left, document.documentElement.offsetWidth);
} else {
width = Math.min(this.getContainerFillWidth(), document.documentElement.offsetWidth - this.getWorkspaceOffset().left, document.documentElement.offsetWidth);
}

if (scrollHandler !== window){
var overflow = this.instance.wtScrollbars.horizontal.scrollHandler.style.overflow;

if (overflow == "scroll" || overflow == "hidden" || overflow == "auto") {
//this is used in `scroll.html`
//TODO test me
return Math.max(width, scrollHandler.clientWidth);
}
else {
return Math.max(width, Handsontable.Dom.outerWidth(this.instance.wtTable.TABLE));
}
}

//this is used in `stretch.html`, `stretch_window.html`
//TODO test me
return Math.max(width, Handsontable.Dom.outerWidth(this.instance.wtTable.TABLE));
};

WalkontableViewport.prototype.sumColumnWidths = function (from, length) {
var sum = 0;
while(from < length) {
sum += this.instance.wtTable.getColumnWidth(from) || this.instance.wtSettings.defaultColumnWidth;
from++;
}
return sum;
};
WalkontableViewport.prototype.getContainerFillWidth = function() {

if(this.containerWidth) {
Expand Down
6 changes: 4 additions & 2 deletions src/3rdparty/walkontable/src/viewportColumnsCalculator.js
Expand Up @@ -11,7 +11,6 @@ function WalkontableViewportColumnsCalculator (width, scrollOffset, totalColumns

var i;
var sum = 0;
var sumAll = 0;
var columnWidth;
var needReverse = true;
var defaultColumnWidth = 50;
Expand All @@ -29,7 +28,10 @@ function WalkontableViewportColumnsCalculator (width, scrollOffset, totalColumns
};

this.refreshStretching = function (width) {
for(i = 0; i < totalColumns; i++) {
var columnWidth;
var sumAll = 0;

for(var i = 0; i < totalColumns; i++) {
columnWidth = getColumnWidth(i);
sumAll +=columnWidth;
}
Expand Down

0 comments on commit 874f892

Please sign in to comment.