Skip to content

Commit 643b2c1

Browse files
authored
fix(igxPivot): Fix width calculations when inside flex container with… (#15057)
1 parent ae1f8b2 commit 643b2c1

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,6 +3208,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32083208
private _columnSelectionMode: GridSelectionMode = GridSelectionMode.none;
32093209

32103210
private lastAddedRowIndex;
3211+
protected isColumnWidthSum = false;
32113212
private _currencyPositionLeft: boolean;
32123213

32133214
private rowEditPositioningStrategy = new RowEditPositionStrategy({
@@ -6496,6 +6497,7 @@ export abstract class IgxGridBaseDirective implements GridType,
64966497

64976498
if (this.width === null || !width) {
64986499
width = this.getColumnWidthSum();
6500+
this.isColumnWidthSum = true;
64996501
}
65006502

65016503
if (this.hasVerticalScroll() && this.width !== null) {
@@ -7325,6 +7327,10 @@ export abstract class IgxGridBaseDirective implements GridType,
73257327
this.resetCachedWidths();
73267328
this.cdr.detectChanges();
73277329
}
7330+
7331+
if (this.isColumnWidthSum) {
7332+
this.calcWidth = this.getColumnWidthSum();
7333+
}
73287334
}
73297335

73307336
protected extractDataFromColumnsSelection(source: any[], formatters = false, headers = false): any[] {

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11651165

11661166
/** @hidden */
11671167
public override featureColumnsWidth() {
1168-
return this.pivotRowWidths;
1168+
return this.pivotRowWidths || 0;
11691169
}
11701170

11711171
/* blazorSuppress */
@@ -1295,7 +1295,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
12951295

12961296
/** @hidden @internal */
12971297
public get pivotPinnedWidth() {
1298-
return this.isPinningToStart ? this.pinnedWidth : this.headerFeaturesWidth;
1298+
return !this._init ? (this.isPinningToStart ? this.pinnedWidth : this.headerFeaturesWidth) : 0;
12991299
}
13001300

13011301
/** @hidden @internal */
@@ -1340,12 +1340,6 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
13401340
this.reflow();
13411341
}
13421342

1343-
protected override getColumnWidthSum(): number {
1344-
let colSum = super.getColumnWidthSum();
1345-
colSum += this.rowDimensions.map(dim => this.rowDimensionWidthToPixels(dim)).reduce((prev, cur) => prev + cur, 0);
1346-
return colSum;
1347-
}
1348-
13491343
/**
13501344
* @hidden @internal
13511345
*/
@@ -2245,6 +2239,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
22452239
dim.autoWidth = maxSize;
22462240
}
22472241
}
2242+
2243+
if (this.isColumnWidthSum) {
2244+
this.calcWidth = this.getColumnWidthSum();
2245+
}
22482246
}
22492247

22502248
/** @hidden @internal */

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ISortingExpression, SortingDirection } from '../../data-operations/sort
1010
import { configureTestSuite } from '../../test-utils/configure-suite';
1111
import { GridFunctions, GridSelectionFunctions } from '../../test-utils/grid-functions.spec';
1212
import { PivotGridFunctions } from '../../test-utils/pivot-grid-functions.spec';
13-
import { IgxPivotGridTestBaseComponent, IgxPivotGridTestComplexHierarchyComponent, IgxTotalSaleAggregate } from '../../test-utils/pivot-grid-samples.spec';
13+
import { IgxPivotGridFlexContainerComponent, IgxPivotGridTestBaseComponent, IgxPivotGridTestComplexHierarchyComponent, IgxTotalSaleAggregate } from '../../test-utils/pivot-grid-samples.spec';
1414
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
1515
import { IgxPivotDateAggregate, IgxPivotNumericAggregate } from './pivot-grid-aggregate';
1616
import { IgxPivotDateDimension } from './pivot-grid-dimensions';
@@ -36,7 +36,8 @@ describe('IgxPivotGrid #pivotGrid', () => {
3636
imports: [
3737
NoopAnimationsModule,
3838
IgxPivotGridTestBaseComponent,
39-
IgxPivotGridTestComplexHierarchyComponent
39+
IgxPivotGridTestComplexHierarchyComponent,
40+
IgxPivotGridFlexContainerComponent
4041
]
4142
}).compileComponents();
4243
}));
@@ -796,6 +797,16 @@ describe('IgxPivotGrid #pivotGrid', () => {
796797
expect(rowHeader[0].nativeElement.offsetHeight).toBe(rowHeightMedium);
797798
});
798799

800+
it('should render with correct width when set to 100% inside of flex container', async() => {
801+
fixture = TestBed.createComponent(IgxPivotGridFlexContainerComponent);
802+
fixture.detectChanges();
803+
await wait(100);
804+
fixture.detectChanges();
805+
const pivotGrid = fixture.componentInstance.pivotGrid;
806+
const colSum = pivotGrid.featureColumnsWidth() + pivotGrid.columns.filter(x => !x.columnGroup).map(x => x.calcPixelWidth).reduce((x, y) => x + y);
807+
const expectedSize = Math.min(window.innerWidth, colSum);
808+
expect(pivotGrid.nativeElement.clientWidth - expectedSize).toBeLessThan(50, "should take sum of columns as width.");
809+
});
799810

800811
describe('IgxPivotGrid Features #pivotGrid', () => {
801812
it('should show excel style filtering via dimension chip.', async () => {
@@ -2418,6 +2429,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
24182429
});
24192430

24202431
it("should position correct the horizontal scrollbar", () => {
2432+
fixture.detectChanges();
24212433
const scrollBarPosition = fixture.nativeElement.querySelector("igx-horizontal-virtual-helper").getBoundingClientRect();
24222434
const displayContainerPosition = fixture.nativeElement.querySelector(".igx-grid__tbody-content").getBoundingClientRect()
24232435
expect(scrollBarPosition.x).toEqual(displayContainerPosition.x);

projects/igniteui-angular/src/lib/test-utils/pivot-grid-samples.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,32 @@ export class IgxPivotGridMultipleRowComponent extends IgxPivotGridTestBaseCompon
346346
}
347347
}
348348

349+
350+
@Component({
351+
styles: `
352+
.pivot-container {
353+
display: flex;
354+
align-items: flex-start;
355+
flex: 1 1 auto;
356+
order: 0;
357+
align-items: stretch;
358+
}
359+
`,
360+
template: `
361+
<div class="pivot-container">
362+
<div>
363+
<igx-pivot-grid #grid [width]="'100%'" [height]="'800px'" [data]="data" [pivotConfiguration]="pivotConfigHierarchy"
364+
[rowSelection]="'single'" [columnSelection]="'single'" [defaultExpandState]="defaultExpand">
365+
</igx-pivot-grid>
366+
</div>
367+
</div>
368+
`,
369+
standalone: true,
370+
imports: [IgxPivotGridComponent]
371+
})
372+
export class IgxPivotGridFlexContainerComponent extends IgxPivotGridTestBaseComponent{
373+
}
374+
349375
export class IgxTotalSaleAggregate {
350376
public static totalSale: PivotAggregation = (members, data: any) =>
351377
data.reduce((accumulator, value) => accumulator + value.UnitPrice * value.UnitsSold, 0);

0 commit comments

Comments
 (0)