Skip to content

Commit 436ef03

Browse files
authored
fix: do not throw when removing sort column after sorting (#6448)
1 parent 783171b commit 436ef03

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/grid/src/vaadin-grid-dynamic-columns-mixin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const DynamicColumnsMixin = (superClass) =>
112112
if (hasColumnElements(info.addedNodes) || hasColumnElements(info.removedNodes)) {
113113
const allRemovedCells = info.removedNodes.flatMap((c) => c._allCells);
114114
const filterNotConnected = (element) =>
115-
allRemovedCells.filter((cell) => cell._content.contains(element)).length;
115+
allRemovedCells.filter((cell) => cell && cell._content.contains(element)).length;
116116

117117
this.__removeSorters(this._sorters.filter(filterNotConnected));
118118
this.__removeFilters(this._filters.filter(filterNotConnected));

‎packages/grid/test/lit.test.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@esm-bundle/chai';
22
import { aTimeout, fixtureSync } from '@vaadin/testing-helpers';
3+
import '../vaadin-grid-sort-column.js';
34
import '../vaadin-grid.js';
45
import { html, render } from 'lit';
56
import { getPhysicalItems } from './helpers.js';
@@ -32,4 +33,31 @@ describe('lit', () => {
3233
const grid = wrapper.firstElementChild;
3334
expect(getPhysicalItems(grid).length).to.equal(1);
3435
});
36+
37+
it('should not throw when dynamically removing sort columns after sorting', async () => {
38+
const wrapper = fixtureSync(`<div></div>`);
39+
40+
function renderGrid(columnPaths, items) {
41+
render(
42+
html`
43+
<vaadin-grid .items=${items}>
44+
${columnPaths.map((columnPath) => {
45+
return html`<vaadin-grid-sort-column path="${columnPath}"></vaadin-grid-sort-column>`;
46+
})}
47+
</vaadin-grid>
48+
`,
49+
wrapper,
50+
);
51+
}
52+
53+
// First render with two columns
54+
renderGrid(['c1', 'c2'], [{ c1: '1-1', c2: '1-2' }]);
55+
56+
await aTimeout(0);
57+
58+
document.querySelector('vaadin-grid-sorter').click();
59+
60+
// Then render a grid with one column
61+
renderGrid(['c1'], [{ c1: '1-1', c2: '1-2' }]);
62+
});
3563
});

0 commit comments

Comments
 (0)