Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add autoResize.autoHeight to resize by dataset length #1519

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/examples/grid-tree-data-hierarchical.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class GridTreeDataHierarchicalComponent implements OnInit {

this.gridOptions = {
autoResize: {
autoHeight: false,
container: '#demo-container',
rightPadding: 10,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ Object.defineProperty(paginationServiceStub, 'totalItems', {
});

const resizerServiceStub = {
isAutoHeightEnabled: true,
autoHeightRecalcRow: 100,
init: jest.fn(),
dispose: jest.fn(),
bindAutoResizeDataGrid: jest.fn(),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,11 @@ export class AngularSlickgridComponent<TData = any> 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) {
Expand Down
4 changes: 3 additions & 1 deletion src/app/modules/angular-slickgrid/global-grid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ export const GlobalGridOptions: Partial<GridOption> = {
autoFitColumnsOnFirstLoad: true,
autoResize: {
applyResizeToContainer: true,
autoHeight: true,
autoHeightRecalcRow: 100,
calculateAvailableSizeBy: 'window',
bottomPadding: 20,
minHeight: 180,
minHeight: 250,
minWidth: 300,
rightPadding: 0,
},
Expand Down
Loading