Skip to content

Commit faa5337

Browse files
refactor: improve grid column group auto-width performance (#5122) (#5125)
Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
1 parent 41eff1d commit faa5337

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

packages/grid/src/vaadin-grid.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,18 @@ class Grid extends ElementMixin(
543543

544544
/** @private */
545545
__getIntrinsicWidth(col) {
546+
if (this.__intrinsicWidthCache.has(col)) {
547+
return this.__intrinsicWidthCache.get(col);
548+
}
549+
550+
const width = this.__calculateIntrinsicWidth(col);
551+
this.__intrinsicWidthCache.set(col, width);
552+
553+
return width;
554+
}
555+
556+
/** @private */
557+
__calculateIntrinsicWidth(col) {
546558
const initialWidth = col.width;
547559
const initialFlexGrow = col.flexGrow;
548560

@@ -615,6 +627,8 @@ class Grid extends ElementMixin(
615627
this._debouncerHiddenChanged.flush();
616628
}
617629

630+
this.__intrinsicWidthCache = new Map();
631+
618632
cols.forEach((col) => {
619633
col.width = `${this.__getDistributedWidth(col)}px`;
620634
});

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ describe('column auto-width', () => {
148148
await recalculateWidths();
149149
expectColumnWidthsToBeOk(columns);
150150
});
151+
152+
it('should update column width when recalculating widths', async () => {
153+
grid.items = testItems;
154+
await recalculateWidths();
155+
expectColumnWidthsToBeOk(columns, [74]);
156+
157+
// Update item text in first column
158+
grid.items = [{ a: 'foo bar baz' }];
159+
await nextFrame();
160+
grid.recalculateColumnWidths();
161+
expectColumnWidthsToBeOk(columns, [114]);
162+
});
151163
});
152164

153165
describe('tree column', () => {

0 commit comments

Comments
 (0)