Skip to content

Commit a2c5097

Browse files
committed
fix(pivotGrid): Change how horizontal cell width is initally calculated for auto size.
Try to also mitigate row headers auto width not calculated correctly on clean load.
1 parent 2d50f68 commit a2c5097

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -1599,14 +1599,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
15991599
public autoSizeRowDimension(dimension: IPivotDimension) {
16001600
if (this.getDimensionType(dimension) === PivotDimensionType.Row) {
16011601
const relatedDims: string[] = PivotUtil.flatten([dimension]).map((x: IPivotDimension) => x.memberName);
1602-
let contentCollection = [];
1603-
if (this.hasHorizontalLayout) {
1604-
const allMrlContents = this.rowDimensionMrlRowsCollection.map(mrlRow => mrlRow.contentCells.toArray()).flat();
1605-
contentCollection = allMrlContents.filter(cell => cell.rootDimension === dimension);
1606-
} else {
1607-
contentCollection = this.rowDimensionContentCollection.toArray();
1608-
}
1609-
1602+
const contentCollection = this.getContentCollection(dimension);
16101603
const content = contentCollection.filter(x => relatedDims.indexOf(x.dimension.memberName) !== -1);
16111604
const headers = content.map(x => x.headerGroups.toArray()).flat().map(x => x.header && x.header.refInstance);
16121605
if (this.pivotUI.showRowHeaders) {
@@ -1950,10 +1943,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
19501943
}
19511944

19521945
protected getPivotRowHeaderContentWidth(headerGroup: IgxPivotRowHeaderGroupComponent) {
1953-
const headerStyle = this.document.defaultView.getComputedStyle(headerGroup.header.refInstance.nativeElement);
1954-
const headerPadding = parseFloat(headerStyle.paddingLeft) + parseFloat(headerStyle.paddingRight) +
1955-
parseFloat(headerStyle.borderRightWidth);
1956-
return this.getHeaderCellWidth(headerGroup.header.refInstance.nativeElement).width + headerPadding;
1946+
const headerSizes = this.getHeaderCellWidth(headerGroup.header.refInstance.nativeElement);
1947+
return headerSizes.width + headerSizes.padding;
19571948
}
19581949

19591950
protected getLargesContentWidth(contents: ElementRef[]): string {
@@ -2160,29 +2151,45 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
21602151
if (this.hasDimensionsToAutosize) {
21612152
this.cdr.detectChanges();
21622153
this.zone.onStable.pipe(first()).subscribe(() => {
2163-
this.autoSizeDimensionsInView();
2154+
requestAnimationFrame(() => {
2155+
this.autoSizeDimensionsInView();
2156+
});
21642157
});
21652158
}
21662159
}
21672160

2161+
protected getContentCollection(dimenstion: IPivotDimension) {
2162+
let contentCollection;
2163+
if (this.hasHorizontalLayout) {
2164+
const allMrlContents = this.rowDimensionMrlRowsCollection.map(mrlRow => mrlRow.contentCells.toArray()).flat();
2165+
contentCollection = allMrlContents.filter(cell => cell.rootDimension === dimenstion);
2166+
} else {
2167+
contentCollection = this.rowDimensionContentCollection.toArray();
2168+
}
2169+
return contentCollection;
2170+
}
2171+
21682172
protected autoSizeDimensionsInView() {
21692173
if (!this.hasDimensionsToAutosize) return;
21702174
for (const dim of this.visibleRowDimensions) {
2171-
if (dim.width === 'auto' && !this.hasHorizontalLayout) {
2175+
if (dim.width === 'auto') {
21722176
const contentWidths = [];
21732177
const relatedDims = PivotUtil.flatten([dim]).map(x => x.memberName);
2174-
const content = this.rowDimensionContentCollection.filter(x => relatedDims.indexOf(x.dimension.memberName) !== -1);
2178+
const contentCollection = this.getContentCollection(dim);
2179+
const content = contentCollection.filter(x => relatedDims.indexOf(x.dimension.memberName) !== -1);
21752180
const headers = content.map(x => x.headerGroups.toArray()).flat().map(x => x.header && x.header.refInstance);
21762181
headers.forEach((header) => contentWidths.push(header?.nativeElement?.offsetWidth || 0));
2182+
if (this.pivotUI.showRowHeaders) {
2183+
const dimensionHeader = this.theadRow.rowDimensionHeaders.find(x => x.column.field === dim.memberName);
2184+
contentWidths.push(parseFloat(this.getLargesContentWidth([dimensionHeader])));
2185+
}
21772186
const max = Math.max(...contentWidths);
21782187
if (max === 0) {
21792188
// cells not in DOM yet...
21802189
continue;
21812190
}
21822191
const maxSize = Math.ceil(Math.max(...contentWidths));
21832192
dim.autoWidth = maxSize;
2184-
} else if (dim.width === 'auto') {
2185-
this.autoSizeRowDimension(dim);
21862193
}
21872194
}
21882195
}

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-row-dimension-content.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
173173

174174
protected getHeaderWidthFromDimension() {
175175
if (this.grid.hasHorizontalLayout) {
176-
return this.width;
176+
return this.width === -1 ? 'fit-content' : this.width;
177177
}
178178
return this.grid.rowDimensionWidth(this.rootDimension);
179179
}

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-row-dimension-mrl-row.component.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class IgxPivotRowDimensionMrlRowComponent extends IgxGridHeaderRowCompone
101101
} else if (this.grid.visibleRowDimensions && this.grid.dimensionDataColumns) {
102102
const res = [];
103103
this.grid.visibleRowDimensions.forEach(dim => {
104-
res.push(this.grid.rowDimensionWidthToPixels(dim) + "px");
104+
res.push(this.grid.rowDimensionWidth(dim));
105105
});
106106
return res.join(' ');
107107
}
@@ -110,7 +110,12 @@ export class IgxPivotRowDimensionMrlRowComponent extends IgxGridHeaderRowCompone
110110
public rowDimensionWidthCombined(dims: IPivotDimension[]) {
111111
let resWidth = 0;
112112
for (const dim of (dims || [])) {
113-
resWidth += this.grid.rowDimensionWidthToPixels(dim);
113+
const rowDimWidth = this.grid.rowDimensionWidth(dim);
114+
if (rowDimWidth === 'fit-content') {
115+
return -1;
116+
} else {
117+
resWidth += parseFloat(rowDimWidth);
118+
}
114119
}
115120
return resWidth;
116121
}

0 commit comments

Comments
 (0)