Skip to content
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
16 changes: 16 additions & 0 deletions packages/common/src/services/__tests__/resizer.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="node" />

import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';
import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
import { SlickEvent, type SlickDataView, type SlickGrid } from '../../core/index.js';
Expand Down Expand Up @@ -680,6 +682,20 @@ describe('Resizer Service', () => {
expect(mockColDefs[1].width).toBe(56); // longest word "Destinee" (length 8 * charWidth(7) * ratio(0.88)) + cellPadding(6) = 55.28 ceil to => 56
});

it('should leave the column unchanged when the DataView has no accessible items', () => {
const reRenderSpy = vi.spyOn(gridStub, 'reRenderColumns');
const initialWidth = 120;
mockColDefs[1].width = initialWidth;
vi.spyOn(mockDataView, 'getItems').mockReturnValue([]);

mockGridOptions.enableColumnResizeOnDoubleClick = true;
service.init(gridStub, divContainer);
gridStub.onColumnsResizeDblClick.notify({ triggeredByColumn: 'firstName', grid: gridStub });

expect(reRenderSpy).not.toHaveBeenCalled();
expect(mockColDefs[1].width).toBe(initialWidth);
});

it('should call handleSingleColumnResizeByContent when "onHeaderMenuColumnResizeByContent" gets triggered but expect a resized column width when left section width becomes greater than full viewport width', () => {
const viewportLeft = document.createElement('div');
viewportLeft.className = 'slick-viewport-left';
Expand Down
9 changes: 9 additions & 0 deletions packages/common/src/services/resizer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ export class ResizerService {
}

protected handleSingleColumnResizeByContent(columnId: string): void {
// A custom DataView might not expose all rows through getItems() (for example, a windowed
// DataView can intentionally return an empty array). In that case we cannot calculate a
// content width, so leave the current column width unchanged and let the consumer provide
// its own resize handler if it can fetch the rows asynchronously.
const dataItems = this.dataView?.getItems?.();
if (!Array.isArray(dataItems) || dataItems.length === 0) {
return;
}

const columns = this._grid.getColumns();
const columnDefIdx = columns.findIndex((col) => col.id === columnId);

Expand Down
Loading