diff --git a/packages/common/src/services/__tests__/resizer.service.spec.ts b/packages/common/src/services/__tests__/resizer.service.spec.ts index 6d0a9bf4c..c9d5267f8 100644 --- a/packages/common/src/services/__tests__/resizer.service.spec.ts +++ b/packages/common/src/services/__tests__/resizer.service.spec.ts @@ -646,6 +646,25 @@ describe('Resizer Service', () => { expect(reRenderColumnsSpy).toHaveBeenCalledWith(true); }); + it('should not return without resizing if "resizeByContentOnlyOnFirstLoad" is set to True and we already resized once', () => { + const setColumnsSpy = jest.spyOn(gridStub, 'setColumns'); + const reRenderColumnsSpy = jest.spyOn(gridStub, 'reRenderColumns'); + const pubSubSpy = jest.spyOn(eventPubSubService, 'publish'); + + service.init(gridStub, divContainer); + service.resizeColumnsByCellContent(true); + + expect(setColumnsSpy).toHaveBeenCalled(); + expect(reRenderColumnsSpy).toHaveBeenCalledWith(true); + expect(pubSubSpy).toHaveBeenCalledWith('onBeforeResizeByContent', undefined, 0); + + // calling a 2nd time should cancel any resize + // so we shouldn't expect the grid.setColumns to be called again + mockGridOptions.resizeByContentOnlyOnFirstLoad = true; + service.resizeColumnsByCellContent(false); + expect(setColumnsSpy).toHaveBeenCalledTimes(1); + }); + it('should call the resize and expect first column have a fixed width while other will have a calculated width when resizing by their content and grid is editable', () => { const setColumnsSpy = jest.spyOn(gridStub, 'setColumns'); const reRenderColumnsSpy = jest.spyOn(gridStub, 'reRenderColumns'); diff --git a/packages/common/src/services/resizer.service.ts b/packages/common/src/services/resizer.service.ts index a964cb204..b796035f8 100644 --- a/packages/common/src/services/resizer.service.ts +++ b/packages/common/src/services/resizer.service.ts @@ -398,12 +398,12 @@ export class ResizerService { const viewportWidth = this._gridParentContainerElm?.offsetWidth ?? 0; // if our columns total width is smaller than the grid viewport, we can call the column autosize directly without the need to recalculate all column widths - if (!recalculateColumnsTotalWidth && this._totalColumnsWidthByContent > 0 && this._totalColumnsWidthByContent < viewportWidth) { + if ((!Array.isArray(dataset) || dataset.length === 0) || (!recalculateColumnsTotalWidth && this._totalColumnsWidthByContent > 0 && this._totalColumnsWidthByContent < viewportWidth)) { this._grid.autosizeColumns(); return; } - if ((!Array.isArray(dataset) || dataset.length === 0) || (this._hasResizedByContentAtLeastOnce && this.gridOptions?.resizeByContentOnlyOnFirstLoad && !recalculateColumnsTotalWidth)) { + if ((this._hasResizedByContentAtLeastOnce && this.gridOptions?.resizeByContentOnlyOnFirstLoad && !recalculateColumnsTotalWidth)) { return; } diff --git a/packages/vanilla-force-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip b/packages/vanilla-force-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip index e92d21601..4acdbcc05 100644 Binary files a/packages/vanilla-force-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip and b/packages/vanilla-force-bundle/dist-grid-bundle-zip/slickgrid-vanilla-bundle.zip differ