Skip to content

Commit b42e8f8

Browse files
authored
fix(igxPivot): Fix width calculations when inside flex container with… (#15058)
1 parent 92a0949 commit b42e8f8

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -3201,6 +3201,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32013201
private _columnSelectionMode: GridSelectionMode = GridSelectionMode.none;
32023202

32033203
private lastAddedRowIndex;
3204+
protected isColumnWidthSum = false;
32043205
private _currencyPositionLeft: boolean;
32053206

32063207
private rowEditPositioningStrategy = new RowEditPositionStrategy({
@@ -6488,6 +6489,7 @@ export abstract class IgxGridBaseDirective implements GridType,
64886489

64896490
if (this.width === null || !width) {
64906491
width = this.getColumnWidthSum();
6492+
this.isColumnWidthSum = true;
64916493
}
64926494

64936495
if (this.hasVerticalScroll() && this.width !== null) {
@@ -7311,6 +7313,10 @@ export abstract class IgxGridBaseDirective implements GridType,
73117313
this.resetCachedWidths();
73127314
this.cdr.detectChanges();
73137315
}
7316+
7317+
if (this.isColumnWidthSum) {
7318+
this.calcWidth = this.getColumnWidthSum();
7319+
}
73147320
}
73157321

73167322
protected extractDataFromColumnsSelection(source: any[], formatters = false, headers = false): any[] {
@@ -7769,7 +7775,7 @@ export abstract class IgxGridBaseDirective implements GridType,
77697775
} else {
77707776
this._shouldRecalcRowHeight = true;
77717777
}
7772-
}
7778+
}
77737779
}
77747780

77757781
// TODO: About to Move to CRUD

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11661166

11671167
/** @hidden */
11681168
public override featureColumnsWidth() {
1169-
return this.pivotRowWidths;
1169+
return this.pivotRowWidths || 0;
11701170
}
11711171

11721172
/* blazorSuppress */
@@ -1296,7 +1296,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
12961296

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

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

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

22512249
/** @hidden @internal */

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

+14-2
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

+26
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,32 @@ export class IgxPivotGridMultipleRowComponent extends IgxPivotGridTestBaseCompon
350350
}
351351
}
352352

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

0 commit comments

Comments
 (0)