Skip to content

Commit 41b4fc4

Browse files
authored
fix: recalculate column widths on initial item load with same data provider (#9859)
1 parent ac3551e commit 41b4fc4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

packages/grid/src/vaadin-grid-column-auto-width-mixin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ export const ColumnAutoWidthMixin = (superClass) =>
5959
}
6060

6161
/** @private */
62-
__flatSizeChangedAutoWidth() {
62+
__flatSizeChangedAutoWidth(flatSize) {
6363
// Flat size changed, recalculate column widths if pending (asynchronously, to allow grid to render row elements first)
64-
requestAnimationFrame(() => this.__tryToRecalculateColumnWidthsIfPending());
64+
requestAnimationFrame(() => {
65+
if (!!flatSize && !this.__hasHadRenderedRowsForColumnWidthCalculation) {
66+
this.recalculateColumnWidths();
67+
} else {
68+
this.__tryToRecalculateColumnWidthsIfPending();
69+
}
70+
});
6571
}
6672

6773
/**

packages/grid/test/column-auto-width.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,26 @@ describe('column auto-width', () => {
354354
expect(parseFloat(lastColumn.width)).not.to.be.lessThan(getCellIntrinsicWidth(frozenToEndHeaderCell));
355355
});
356356

357+
it('should recalculate column widths on initial item load without data provider change', async () => {
358+
let items = [];
359+
grid.dataProvider = (_, cb) => cb(items, items.length);
360+
await nextFrame();
361+
362+
// Should recalculate once on initial load of items
363+
spy.resetHistory();
364+
items = [testItems[0], testItems[1]];
365+
grid.size = items.length;
366+
await nextFrame();
367+
expect(spy.callCount).to.equal(1);
368+
369+
// Should not recalculate on further update of items
370+
spy.resetHistory();
371+
items = [...items, testItems[2]];
372+
grid.size = items.length;
373+
await nextFrame();
374+
expect(spy.called).to.be.false;
375+
});
376+
357377
describe('focusButtonMode column', () => {
358378
beforeEach(async () => {
359379
const column = document.createElement('vaadin-grid-column');

0 commit comments

Comments
 (0)