Skip to content

Commit 0d56c73

Browse files
authored
fix(IgxGrid): Do not apply width constraint to groups. (#17071)
1 parent 0018afe commit 0d56c73

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

projects/igniteui-angular/src/lib/grids/columns/column.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,8 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
22232223
result.push(size.width + 'px');
22242224
} else {
22252225
const currentWidth = parseFloat(this.grid.getPossibleColumnWidth());
2226-
result.push((this.getConstrainedSizePx(currentWidth)) + 'px');
2226+
const target = size && size.ref ? size.ref : this;
2227+
result.push((target as IgxColumnComponent).getConstrainedSizePx(currentWidth) + 'px');
22272228
}
22282229
}
22292230
return result;
@@ -2716,7 +2717,7 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
27162717
} else if (this.minWidth && newSize <= this.userSetMinWidthPx) {
27172718
this.widthConstrained = true;
27182719
return this.userSetMinWidthPx;
2719-
} else if (!this.minWidth && (!this.widthSetByUser || this.width === 'fit-content') && !this.grid.columnWidthSetByUser && (!newSize || newSize <= this.grid.minColumnWidth)) {
2720+
} else if (!this.columnGroup && !this.minWidth && (!this.widthSetByUser || this.width === 'fit-content') && !this.grid.columnWidthSetByUser && (!newSize || newSize <= this.grid.minColumnWidth)) {
27202721
return this.grid.minColumnWidth;
27212722
} else {
27222723
this.widthConstrained = false;

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import {
55
CollapsibleColumnGroupTestComponent,
66
CollapsibleGroupsTemplatesTestComponent,
7-
CollapsibleGroupsDynamicColComponent
7+
CollapsibleGroupsDynamicColComponent,
8+
CollapsibleGroupWithExplicitChildWidthsComponent
89
} from '../../test-utils/grid-samples.spec';
910
import { GridFunctions } from '../../test-utils/grid-functions.spec';
1011
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
@@ -28,7 +29,8 @@ describe('IgxGrid - multi-column headers #grid', () => {
2829
NoopAnimationsModule,
2930
CollapsibleColumnGroupTestComponent,
3031
CollapsibleGroupsTemplatesTestComponent,
31-
CollapsibleGroupsDynamicColComponent
32+
CollapsibleGroupsDynamicColComponent,
33+
CollapsibleGroupWithExplicitChildWidthsComponent
3234
]
3335
}).compileComponents();
3436
}));
@@ -617,6 +619,28 @@ describe('IgxGrid - multi-column headers #grid', () => {
617619
expect(spans.length).toBe(2);
618620
});
619621

622+
it('should not constrain collapsed column group width by default min width when children have explicit widths (#17042)', () => {
623+
const fix = TestBed.createComponent(CollapsibleGroupWithExplicitChildWidthsComponent);
624+
fix.detectChanges();
625+
const g: IgxGridComponent = fix.componentInstance.grid;
626+
627+
const customerInfoGroup = GridFunctions.getColGroup(g, 'Customer Information');
628+
expect(customerInfoGroup.expanded).toBe(false);
629+
expect(customerInfoGroup.collapsible).toBe(true);
630+
631+
// The only visible child when collapsed is CompanyName with width 100px.
632+
const visibleChildren = customerInfoGroup.children
633+
.filter(c => !c.hidden);
634+
expect(visibleChildren.length).toBe(1);
635+
636+
const visibleChildWidth = visibleChildren
637+
.reduce((sum, c) => sum + c.calcPixelWidth, 0);
638+
639+
const groupWidth = customerInfoGroup.calcPixelWidth;
640+
expect(groupWidth).toBe(visibleChildWidth);
641+
expect(groupWidth).toBe(100);
642+
});
643+
620644
it('Group By: test when group by a column', () => {
621645
addressInf.expanded = false;
622646
countryCol.visibleWhenCollapsed = false;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,3 +2812,26 @@ export class IgxGridRowEditingDefinedColumnsComponent extends BasicGridComponent
28122812
})
28132813
export class IgxGridConditionalFilteringComponent extends IgxGridFilteringComponent {
28142814
}
2815+
2816+
@Component({
2817+
template: `
2818+
<igx-grid #grid [data]="data" height="500px" width="600px">
2819+
<igx-column-group header="Customer Information" [collapsible]="true" [expanded]="false">
2820+
<igx-column field="CompanyName" width="100px" [visibleWhenCollapsed]="true"></igx-column>
2821+
<igx-column field="ContactName" width="100px" [visibleWhenCollapsed]="false"></igx-column>
2822+
<igx-column field="ContactTitle" width="100px" [visibleWhenCollapsed]="false"></igx-column>
2823+
</igx-column-group>
2824+
<igx-column field="ID" width="200px"></igx-column>
2825+
<igx-column field="Address" width="200px"></igx-column>
2826+
<igx-column field="City" width="200px"></igx-column>
2827+
<igx-column field="Country" width="200px"></igx-column>
2828+
<igx-column field="Phone" width="200px"></igx-column>
2829+
</igx-grid>
2830+
`,
2831+
imports: [IgxGridComponent, IgxColumnComponent, IgxColumnGroupComponent]
2832+
})
2833+
export class CollapsibleGroupWithExplicitChildWidthsComponent {
2834+
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
2835+
public grid: IgxGridComponent;
2836+
public data = SampleTestData.contactInfoDataFull();
2837+
}

0 commit comments

Comments
 (0)