Skip to content

Commit 39ce07d

Browse files
authored
fix: handle showing hidden column while clearing grid filter (#2200)
1 parent 0777972 commit 39ce07d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/vaadin-grid-column.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,15 @@
322322
}
323323

324324
cells.forEach(cell => {
325-
const model = this._grid.__getRowModel(cell.parentElement);
325+
const parent = cell.parentElement;
326+
327+
// When a column is made hidden and shown again, in some instances it breaks rendering of rows for grid
328+
// this happens when parent element of cell is null, which might not be set correctly during rendering
329+
// the newly shown column, this check simply avoid that case
330+
if (!parent) {
331+
return;
332+
}
333+
const model = this._grid.__getRowModel(parent);
326334

327335
if (renderer) {
328336
cell._renderer = renderer;

test/filtering.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@
7070
</template>
7171
</test-fixture>
7272

73+
<test-fixture id="grid-with-external-filter">
74+
<template>
75+
<vaadin-grid>
76+
<vaadin-grid-column path="first"></vaadin-grid-column>
77+
<vaadin-grid-column id="last" path="last"></vaadin-grid-column>
78+
</vaadin-grid>
79+
</template>
80+
</test-fixture>
81+
7382
<script>
7483

7584
describe('filter', () => {
@@ -331,6 +340,40 @@
331340
});
332341

333342
});
343+
344+
describe('in-memory filtering and hiding a column', () => {
345+
it('should correctly display items after filter is cleared and column is made visible', () => {
346+
const grid = fixture('grid-with-external-filter');
347+
const column = grid.querySelector('#last');
348+
// this is the minimum amount of items that should be in data-provider in order to see the bug
349+
const itemCount = 56;
350+
const items = Array.apply(null, Array(itemCount)).map((_, i) => {
351+
return {
352+
first: 'foo' + i,
353+
last: 'bar' + i
354+
};
355+
});
356+
grid.items = items;
357+
flushGrid(grid);
358+
359+
// filter the data and hide one column
360+
column.hidden = true;
361+
grid.items = items.filter(item => item.first === 'foo55');
362+
flushGrid(grid);
363+
364+
// clear filter and show column again
365+
column.hidden = false;
366+
grid.items = items;
367+
flushGrid(grid);
368+
369+
// get cell content of 5th row and check if it is displayed correctly
370+
const bodyRows = getRows(grid.$.items);
371+
const rowCells = getRowCells(bodyRows[5]);
372+
const cellContent = getCellContent(rowCells[1]).textContent;
373+
374+
expect(cellContent).to.be.equal('bar5');
375+
});
376+
});
334377
</script>
335378

336379
</body>

0 commit comments

Comments
 (0)