From 26838d96191b46c2876887df3db164cf2c176a75 Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Sat, 25 Jan 2025 13:21:25 -0500 Subject: [PATCH 1/2] fix: add `autoResize.autoHeight` to resize by dataset length --- src/app/examples/grid-tree-data-hierarchical.component.ts | 1 + .../components/angular-slickgrid.component.ts | 5 +++++ src/app/modules/angular-slickgrid/global-grid-options.ts | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/examples/grid-tree-data-hierarchical.component.ts b/src/app/examples/grid-tree-data-hierarchical.component.ts index 63278368..c2669cd2 100644 --- a/src/app/examples/grid-tree-data-hierarchical.component.ts +++ b/src/app/examples/grid-tree-data-hierarchical.component.ts @@ -138,6 +138,7 @@ export class GridTreeDataHierarchicalComponent implements OnInit { this.gridOptions = { autoResize: { + autoHeight: false, container: '#demo-container', rightPadding: 10, }, diff --git a/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts b/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts index 0c215b71..02dab80b 100644 --- a/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts +++ b/src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts @@ -1262,6 +1262,11 @@ export class AngularSlickgridComponent implements AfterViewInit, On if (this._isLocalGrid && this.gridOptions?.enableEmptyDataWarningMessage) { this.displayEmptyDataWarning(currentPageRowItemCount === 0); } + + // when autoResize.autoHeight is enabled, we'll want to call a resize + if (this.gridOptions.enableAutoResize && this.resizerService.isAutoHeightEnabled && currentPageRowItemCount > 0) { + this.resizerService.resizeGrid(); + } } protected initializePaginationService(paginationOptions: Pagination) { diff --git a/src/app/modules/angular-slickgrid/global-grid-options.ts b/src/app/modules/angular-slickgrid/global-grid-options.ts index 19a47e9c..0dc2042f 100644 --- a/src/app/modules/angular-slickgrid/global-grid-options.ts +++ b/src/app/modules/angular-slickgrid/global-grid-options.ts @@ -18,9 +18,11 @@ export const GlobalGridOptions: Partial = { autoFitColumnsOnFirstLoad: true, autoResize: { applyResizeToContainer: true, + autoHeight: true, + autoHeightRecalcRow: 100, calculateAvailableSizeBy: 'window', bottomPadding: 20, - minHeight: 180, + minHeight: 250, minWidth: 300, rightPadding: 0, }, From 683b716e32aea1291ede78e385631378a8bc19ac Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Sat, 25 Jan 2025 13:31:40 -0500 Subject: [PATCH 2/2] chore: add missing test coverage --- .../angular-slickgrid.component.spec.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts b/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts index 4d7ce306..706b9668 100644 --- a/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts +++ b/src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts @@ -183,6 +183,8 @@ Object.defineProperty(paginationServiceStub, 'totalItems', { }); const resizerServiceStub = { + isAutoHeightEnabled: true, + autoHeightRecalcRow: 100, init: jest.fn(), dispose: jest.fn(), bindAutoResizeDataGrid: jest.fn(), @@ -2272,6 +2274,32 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () = expect(footerSpy).toHaveBeenCalledWith(expectation); }); + it('should call a grid resize when the DataView "onRowCountChanged" event is triggered with a low dataset length and autoResize.autoHeight is enabled', () => { + const mockData = [ + { firstName: 'John', lastName: 'Doe' }, + { firstName: 'Jane', lastName: 'Smith' }, + ]; + const invalidateSpy = jest.spyOn(mockGrid, 'invalidate'); + const expectation = { + startTime: expect.any(Date), + endTime: expect.any(Date), + itemCount: 2, + totalItemCount: 2, + }; + jest.spyOn(mockDataView, 'getItemCount').mockReturnValue(mockData.length); + jest.spyOn(mockDataView, 'getFilteredItemCount').mockReturnValue(mockData.length); + jest.spyOn(mockDataView, 'getLength').mockReturnValue(mockData.length); + const resizerSpy = jest.spyOn(resizerServiceStub, 'resizeGrid'); + + component.gridOptions = { enableAutoResize: true, autoResize: { autoHeight: true } }; + component.initialization(slickEventHandler); + mockDataView.onRowCountChanged.notify({ current: 2, previous: 0, dataView: mockDataView, itemCount: 0, callingOnRowsChanged: false }); + + expect(invalidateSpy).toHaveBeenCalled(); + expect(component.metrics).toEqual(expectation); + expect(resizerSpy).toHaveBeenCalled(); + }); + it('should have custom footer with metrics when the DataView "onSetItemsCalled" event is triggered', () => { const expectation = { startTime: expect.toBeDate(),