Skip to content

Commit

Permalink
Do not visit cells twice in the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Sep 28, 2016
1 parent 63bf528 commit 40439ee
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions vaadin-grid-table-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,24 @@
this.debounce('_updateCells', function() {
// columns > cells means that there is an extra col for multiselection
var multiSel = this.columns.length > this.cells.length ? 1 : 0;
var spanning = 0;
this.cells.forEach(function(cell, index) {
var width = this.columns[index + multiSel].width;
var flex = this.columns[index + multiSel].flex;
// spanning > 0 means that this row is already spanned
if (!spanning && cell.colspan > 1) {
spanning = cell.colspan;
for (var i = 1; i < spanning; i++) {
width += ' + ' + this.columns[index + multiSel + i].width;
flex += this.columns[index + multiSel + i].flex;
}

for (var i = 0, l = this.cells.length, colspan; i < l; i += colspan) {
var cell = this.cells[i];
colspan = cell.colspan || 1;
var width = this.columns[i + multiSel].width;
var flex = this.columns[i + multiSel].flex;

// Visit colspanned cells to hide then and increase width and flex of parent
for (var j = 1; j < colspan && i + j < l; j++) {
this.cells[i + j].style.display = 'none';
width = width + ' + ' + this.columns[i + multiSel + j].width;
flex += this.columns[i + multiSel + j].flex;
}

cell.style.flexBasis = 'calc(' + width + ')';
cell.style.flexGrow = flex;
cell.style.display = (!cell.colspan && spanning > 0) ? 'none' : '';
spanning = Math.max(0, spanning - 1);

}.bind(this));
cell.style.display = '';
}
}.bind(this));
},

Expand Down

0 comments on commit 40439ee

Please sign in to comment.