Skip to content

Commit ec2d13b

Browse files
authored
Merge pull request #8560 from IgniteUI/mkirova/fix-8555-10.1.x
fix(igxGrid): Do not set calcWidth to the original width propety. Use…
2 parents b93361d + dc1f4b3 commit ec2d13b

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4949,11 +4949,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
49494949
const cols = this.hasColumnLayouts ?
49504950
this.visibleColumns.filter(x => x.columnLayout) : this.visibleColumns.filter(x => !x.columnGroup);
49514951
cols.forEach((item) => {
4952-
const isWidthInPercent = item.width && typeof item.width === 'string' && item.width.indexOf('%') !== -1;
4953-
if (isWidthInPercent) {
4954-
item.width = item.calcWidth || MINIMUM_COLUMN_WIDTH + 'px';
4955-
}
4956-
colSum += parseInt((item.width || item.defaultWidth), 10) || MINIMUM_COLUMN_WIDTH;
4952+
colSum += parseInt((item.calcWidth || item.defaultWidth), 10) || MINIMUM_COLUMN_WIDTH;
49574953
});
49584954
if (!colSum) {
49594955
return null;

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,30 @@ describe('IgxGrid Component Tests #grid', () => {
16591659
expect(cells.length).toBe(30);
16601660
expect(parseInt(grid.hostWidth, 10)).toBe(30 * 136);
16611661
});
1662+
1663+
it('should retain column with in % after hiding/showing grid with 100% width', () => {
1664+
const fix = TestBed.createComponent(IgxGridColumnPercentageWidthComponent);
1665+
fix.componentInstance.initColumnsRows(5, 3);
1666+
const grid = fix.componentInstance.grid;
1667+
fix.detectChanges();
1668+
grid.width = '100%';
1669+
fix.detectChanges();
1670+
grid.columns[0].width = '50%';
1671+
fix.detectChanges();
1672+
1673+
// hide
1674+
grid.nativeElement.style.display = 'none';
1675+
// simulate resize observer reflow
1676+
grid.reflow();
1677+
1678+
expect(grid.columns[0].width).toBe('50%');
1679+
1680+
grid.nativeElement.style.display = '';
1681+
// simulate resize observer reflow
1682+
grid.reflow();
1683+
1684+
expect(grid.columns[0].width).toBe('50%');
1685+
});
16621686
});
16631687

16641688
describe('IgxGrid - API methods', () => {

src/app/grid-auto-size/grid-auto-size.sample.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<button igxButton="raised" (click)=" setData(5)">Set small data - 5</button>
2222
<button igxButton="raised" (click)=" setData(3)">Set small data - 3</button>
2323
<button igxButton="raised" (click)="setData(0)">Set no data</button>
24+
<button igxButton="raised" (click)="checkCols()">Check cols</button>
2425
</div>
2526
<div [hidden]='gridContainerHidden' [style.height]='containerHeight'>
2627
<igx-grid
@@ -32,7 +33,7 @@
3233
[rowSelection]="selectionMode"
3334
[filterMode]="'excelStyleFilter'"
3435
[paging]="false"
35-
[width]="'800px'"
36+
[width]="'100%'"
3637
[height]="height">
3738
<igx-column *ngFor="let c of columns" [field]="c.field"
3839
[header]="c.field"

src/app/grid-auto-size/grid-auto-size.sample.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export class GridAutoSizeSampleComponent implements OnInit {
3333

3434
// tslint:disable: max-line-length
3535
this.columns = [
36-
{ field: 'ID', width: 150, resizable: true, movable: true, sortable: false, filterable: true, groupable: true, summary: true, type: 'string' },
37-
{ field: 'CompanyName', width: 150, resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string'},
38-
{ field: 'ContactName', width: 150, resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string' },
39-
{ field: 'ContactTitle', width: 150, resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string' },
36+
{ field: 'ID', width: '25%', resizable: true, movable: true, sortable: false, filterable: true, groupable: true, summary: true, type: 'string' },
37+
{ field: 'CompanyName', width: '25%', resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string'},
38+
{ field: 'ContactName', width: '25%', resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string' },
39+
{ field: 'ContactTitle', width: '25%', resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string' },
4040
{ field: 'Address', width: 150, resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string' },
4141
{ field: 'City', width: 150, resizable: true, movable: true, sortable: false, filterable: false, groupable: true, summary: true, type: 'string' },
4242
{ field: 'Region', width: 150, resizable: true, movable: true, sortable: true, filterable: true, groupable: true, summary: true, type: 'string' },
@@ -55,6 +55,11 @@ export class GridAutoSizeSampleComponent implements OnInit {
5555
this.density = this.displayDensities[event.index].label;
5656
}
5757

58+
checkCols(): void {
59+
const columns = this.grid1.columns;
60+
columns.forEach(c => console.log(c.width));
61+
}
62+
5863

5964
setData(count?) {
6065
this.data = SAMPLE_DATA.slice(0, count);

0 commit comments

Comments
 (0)