Skip to content

Commit 8d06aa6

Browse files
authored
Merge branch '21.2.x' into vkombov/fix-17465-21.2.x
2 parents 5b9578b + 433bb64 commit 8d06aa6

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,10 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
16751675
super.ngOnInit();
16761676
this.removeScrollEventListeners();
16771677
const destructor = takeUntil<any>(this.destroy$);
1678-
this.viewObserver = new (getResizeObserver())((entries: ResizeObserverEntry[]) => this.viewResizeNotify.next(entries));
1678+
const resizeObserver = getResizeObserver();
1679+
if (resizeObserver) {
1680+
this.viewObserver = new resizeObserver((entries: ResizeObserverEntry[]) => this.viewResizeNotify.next(entries));
1681+
}
16791682
this.viewResizeNotify.pipe(
16801683
filter(() => this.igxForContainerSize && this.igxForOf && this.igxForOf.length > 0),
16811684
destructor

projects/igniteui-angular/grids/grid/src/column.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,54 @@ describe('IgxGrid - Column properties #grid', () => {
15631563
expect(grid.columns.find(x => x.field === 'Fax').width).toBe('130px');
15641564
}));
15651565

1566+
it('should rebuild horizontal size cache for auto-sized columns when scrolled into view.', (fakeAsync(() => {
1567+
const fix = TestBed.createComponent(ResizableColumnsComponent);
1568+
const cols = [];
1569+
const data = [];
1570+
for (let j = 0; j < 20; j++) {
1571+
cols.push({
1572+
field: (j + 1).toString(),
1573+
width: 'auto'
1574+
});
1575+
}
1576+
const obj = {};
1577+
for (let j = 0; j < cols.length; j++) {
1578+
const col = cols[j].field;
1579+
obj[col] = j;
1580+
}
1581+
1582+
for (let i = 0; i < 100; i++) {
1583+
const newObj = Object.create(obj);
1584+
newObj['ID'] = i;
1585+
data.push(newObj);
1586+
}
1587+
fix.componentInstance.columns = cols;
1588+
fix.componentInstance.data = data;
1589+
fix.detectChanges();
1590+
tick(100);
1591+
fix.detectChanges();
1592+
const grid = fix.componentInstance.instance;
1593+
let state = grid.headerContainer.state;
1594+
let visibleColumnSizes = (grid.headerContainer as any).individualSizeCache.slice(state.startIndex, state.startIndex + state.chunkSize);
1595+
const expectedAutoSize = 68;
1596+
for (const val of visibleColumnSizes) {
1597+
expect(val).toBe(expectedAutoSize);
1598+
}
1599+
1600+
const horizontalScroller = grid.headerContainer.getScroll();
1601+
horizontalScroller.scrollLeft = horizontalScroller.scrollWidth;
1602+
horizontalScroller.dispatchEvent(new Event('scroll'));
1603+
tick(100);
1604+
fix.detectChanges();
1605+
1606+
state = grid.headerContainer.state;
1607+
expect(state.startIndex).not.toBe(0);
1608+
visibleColumnSizes = (grid.headerContainer as any).individualSizeCache.slice(state.startIndex, state.startIndex + state.chunkSize);
1609+
for (const val of visibleColumnSizes) {
1610+
expect(val).toBe(expectedAutoSize);
1611+
}
1612+
})));
1613+
15661614
it('should auto-size correctly when cell has custom template', fakeAsync(() => {
15671615
const fix = TestBed.createComponent(ResizableColumnsComponent);
15681616
const grid = fix.componentInstance.instance;

projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7616,6 +7616,9 @@ export abstract class IgxGridBaseDirective implements GridType,
76167616
if (colResized) {
76177617
this.resetCachedWidths();
76187618
this.cdr.detectChanges();
7619+
// Rebuild master's sizesCache once from updated calcPixelWidth values
7620+
this.headerContainer.resolveDataDiff();
7621+
this._horizontalForOfs.forEach(vfor => vfor.resolveDataDiff());
76197622
}
76207623

76217624
if (this.isColumnWidthSum) {

0 commit comments

Comments
 (0)