Skip to content

Commit

Permalink
fix: handle showing hidden column while clearing grid filter (#2200)
Browse files Browse the repository at this point in the history
  • Loading branch information
hdamr authored Dec 21, 2021
1 parent 0777972 commit 39ce07d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/vaadin-grid-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,15 @@
}

cells.forEach(cell => {
const model = this._grid.__getRowModel(cell.parentElement);
const parent = cell.parentElement;

// When a column is made hidden and shown again, in some instances it breaks rendering of rows for grid
// this happens when parent element of cell is null, which might not be set correctly during rendering
// the newly shown column, this check simply avoid that case
if (!parent) {
return;
}
const model = this._grid.__getRowModel(parent);

if (renderer) {
cell._renderer = renderer;
Expand Down
43 changes: 43 additions & 0 deletions test/filtering.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
</template>
</test-fixture>

<test-fixture id="grid-with-external-filter">
<template>
<vaadin-grid>
<vaadin-grid-column path="first"></vaadin-grid-column>
<vaadin-grid-column id="last" path="last"></vaadin-grid-column>
</vaadin-grid>
</template>
</test-fixture>

<script>

describe('filter', () => {
Expand Down Expand Up @@ -331,6 +340,40 @@
});

});

describe('in-memory filtering and hiding a column', () => {
it('should correctly display items after filter is cleared and column is made visible', () => {
const grid = fixture('grid-with-external-filter');
const column = grid.querySelector('#last');
// this is the minimum amount of items that should be in data-provider in order to see the bug
const itemCount = 56;
const items = Array.apply(null, Array(itemCount)).map((_, i) => {
return {
first: 'foo' + i,
last: 'bar' + i
};
});
grid.items = items;
flushGrid(grid);

// filter the data and hide one column
column.hidden = true;
grid.items = items.filter(item => item.first === 'foo55');
flushGrid(grid);

// clear filter and show column again
column.hidden = false;
grid.items = items;
flushGrid(grid);

// get cell content of 5th row and check if it is displayed correctly
const bodyRows = getRows(grid.$.items);
const rowCells = getRowCells(bodyRows[5]);
const cellContent = getCellContent(rowCells[1]).textContent;

expect(cellContent).to.be.equal('bar5');
});
});
</script>

</body>
Expand Down

0 comments on commit 39ce07d

Please # to comment.