Skip to content
Merged
44 changes: 44 additions & 0 deletions projects/igniteui-angular/grids/grid/src/column.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { UIInteractions, wait } from '../../../test-utils/ui-interactions.spec';
import { GridFunctions, GridSummaryFunctions } from '../../../test-utils/grid-functions.spec';
import { clearGridSubs, setupGridScrollDetection } from '../../../test-utils/helper-utils.spec';
import { IgxCellFooterTemplateDirective, IgxCellHeaderTemplateDirective, IgxCellTemplateDirective, IgxColumnComponent, INPUT_DEBOUNCE_TIME_DEFAULT, IgxSummaryTemplateDirective } from 'igniteui-angular/grids/core';
import { IgxGridRowComponent } from './grid-row.component';
import { GridColumnDataType, IgxStringFilteringOperand, SortingDirection } from 'igniteui-angular/core';
Expand Down Expand Up @@ -1539,6 +1540,49 @@ describe('IgxGrid - Column properties #grid', () => {
expect(grid.columns.find(x => x.field === 'Fax').width).toBe('130px');
}));

it('should auto-size column when scrolled into view.', (async () => {
const fix = TestBed.createComponent(ResizableColumnsComponent);
Comment thread
mddragnev marked this conversation as resolved.
Outdated
const cols = [];
const data = [];
for (let j = 0; j < 20; j++) {
cols.push({
field: (j + 1).toString(),
width: 'auto'
});
}
const obj = {};
for (let j = 0; j < cols.length; j++) {
const col = cols[j].field;
obj[col] = j;
}

for (let i = 0; i < 100000; i++) {
const newObj = Object.create(obj);
newObj['ID'] = i;
data.push(newObj);
}
fix.componentInstance.columns = cols;
fix.componentInstance.data = data;
fix.detectChanges();
await fix.whenStable();
const grid = fix.componentInstance.instance;
let state = grid.headerContainer.state;
let visibleColumnSizes = (grid.headerContainer as any).individualSizeCache.slice(state.startIndex, state.startIndex + state.chunkSize);
for (const val of visibleColumnSizes) {
expect(val).toBe(68);
}

setupGridScrollDetection(fix, grid);
grid.navigateTo(0, fix.componentInstance.columns.length -1);

state = grid.headerContainer.state;
visibleColumnSizes = (grid.headerContainer as any).individualSizeCache.slice(state.startIndex, state.startIndex + state.chunkSize);
for (const val of visibleColumnSizes) {
expect(val).toBe(68);
}
clearGridSubs();
}));
Comment thread
mddragnev marked this conversation as resolved.
Outdated

it('should auto-size correctly when cell has custom template', fakeAsync(() => {
const fix = TestBed.createComponent(ResizableColumnsComponent);
const grid = fix.componentInstance.instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7587,6 +7587,9 @@ export abstract class IgxGridBaseDirective implements GridType,
if (colResized) {
this.resetCachedWidths();
this.cdr.detectChanges();
// Rebuild master's sizesCache once from updated calcPixelWidth values
this.headerContainer.resolveDataDiff();
this._horizontalForOfs.forEach(vfor => vfor.resolveDataDiff());
Comment thread
mddragnev marked this conversation as resolved.
}

if (this.isColumnWidthSum) {
Expand Down
Loading