Skip to content

Commit

Permalink
Merge pull request #560 from vaadin/fix/2.0-empty-rows
Browse files Browse the repository at this point in the history
Hide rows with only empty cells
  • Loading branch information
platosha committed Dec 8, 2016
2 parents c9efb72 + 85daea3 commit af949b5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/column-groups.html
Expand Up @@ -134,6 +134,12 @@
</template>
</test-fixture>

<vaadin-grid-column id="extra">
<template class="footer">
Foobar
</template>
</vaadin-grid-column>

<script>
describe('column groups', function() {
var grid, scroller, header, body, footer, headerRows, footerRows;
Expand Down Expand Up @@ -208,14 +214,24 @@
var el = getCellContent(cellOnFirstRow);
expect(window.getComputedStyle(el).borderTopStyle).to.eql('none');
});

it('should have no visible header rows', function() {
headerRows.forEach(function(row) {
expect(row.hidden).to.be.true;
});
});

});

describe('1 column 1 group', function() {
var extraColumn;

beforeEach(function() {
// | | group-0 |
// | header-0 | header-1 | header-2 |
init('1column1group');

extraColumn = document.querySelector('#extra').cloneNode(true);
});

it('the group header cell should ignore changes from child columns', function() {
Expand Down Expand Up @@ -272,6 +288,33 @@
expect(getHeaderCell(1, 1).hasAttribute('frozen')).to.be.true;
expect(getHeaderCell(1, 2).hasAttribute('frozen')).to.be.true;
});

it('should have no hidden header rows', function() {
headerRows.forEach(function(row) {
expect(row.hidden).to.be.false;
});
});

it('should have no visible footer rows', function() {
footerRows.forEach(function(row) {
expect(row.hidden).to.be.true;
});
});

it('should have visible footer rows after adding extra column', function() {
Polymer.dom(grid).appendChild(extraColumn);
Polymer.dom.flush();
expect(getRows(footer)[0].hidden).to.be.false;
expect(getRows(footer)[1].hidden).to.be.true;
});

it('should not have visible footer rows after removing extra column', function() {
Polymer.dom(grid).appendChild(extraColumn);
Polymer.dom.flush();
Polymer.dom(grid).removeChild(extraColumn);
Polymer.dom.flush();
expect(getRows(footer)[0].hidden).to.be.true;
});
});


Expand Down
6 changes: 6 additions & 0 deletions vaadin-grid-table-cell.html
Expand Up @@ -296,10 +296,13 @@

_headerTemplateChanged: function(headerTemplate, target) {
if (headerTemplate !== null && (this._isColumnRow || this.column.localName === 'vaadin-grid-column-group')) {
this._isEmpty = false;
this._templateChanged(headerTemplate, target);
} else {
this._isEmpty = true;
this._templateChanged(document.createElement('template'), target);
}
this.fire('cell-empty-changed');
}
});

Expand All @@ -322,9 +325,12 @@
_footerTemplateChanged: function(footerTemplate, target) {
if (footerTemplate !== null && (this._isColumnRow || this.column.localName === 'vaadin-grid-column-group')) {
this._templateChanged(footerTemplate, target);
this._isEmpty = false;
} else {
this._templateChanged(document.createElement('template'), target);
this._isEmpty = true;
}
this.fire('cell-empty-changed');
}
});

Expand Down
22 changes: 22 additions & 0 deletions vaadin-grid-table-row.html
Expand Up @@ -87,6 +87,12 @@
this.target.$.scroller._frozenCellsChanged();
},

_updateRowVisibility: function() {
this.hidden = this.cells.every(function(cell) {
return cell._isEmpty;
});
},

_rowDetailsCellChanged: function(_rowDetailsCell, target) {
// paddingBottom must be set before update() is called!
// make sure observers are in the correct order!
Expand Down Expand Up @@ -175,6 +181,14 @@
vaadinGridTableRowBehavior
],

observers: [
'_updateRowVisibility(columns)'
],

listeners: {
'cell-empty-changed': '_updateRowVisibility'
},

_createCell: function() {
return document.createElement('th', 'vaadin-grid-table-header-cell');
}
Expand All @@ -188,6 +202,14 @@
vaadinGridTableRowBehavior
],

observers: [
'_updateRowVisibility(columns)'
],

listeners: {
'cell-empty-changed': '_updateRowVisibility'
},

_createCell: function() {
return document.createElement('td', 'vaadin-grid-table-footer-cell');
}
Expand Down

0 comments on commit af949b5

Please sign in to comment.