Skip to content

Commit

Permalink
fix(grid): Fix exception when col width in numbers (#3020)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borislav Kulov committed Nov 20, 2018
1 parent f9d4e01 commit 8910806
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
return acc;
}
if (val.width && val.width.indexOf('%') !== -1) {
if (val.width && val.width.indexOf && val.width.indexOf('%') !== -1) {
isChildrenWidthInPercent = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('IgxGrid - multi-column headers', () => {
EmptyColGridComponent,
OneColPerGroupGridComponent,
NestedColumnGroupsGridComponent,
DynamicGridComponent
DynamicGridComponent,
NumberColWidthGridComponent
],
imports: [
NoopAnimationsModule,
Expand Down Expand Up @@ -1378,6 +1379,13 @@ describe('IgxGrid - multi-column headers', () => {
const colsCount = 2; // 1 col group and 1 col
expect(grid.onColumnInit.emit).toHaveBeenCalledTimes(colsCount);
});

fit('Should not throw exception if multi-column header columns width is set as number', () => {
expect(() => {
const fixture = TestBed.createComponent(NumberColWidthGridComponent);
fixture.detectChanges();
}).not.toThrow();
});
});

@Component({
Expand Down Expand Up @@ -2006,6 +2014,32 @@ export class DynamicGridComponent {
data = SampleTestData.contactInfoDataFull();
}

@Component({
template: `
<igx-grid #grid [data]="data" height="500px">
<igx-column-group header="MCH">
<igx-column *ngFor="let c of columns"
[field]="c.field"
[header]="c.field"
[width]="c.width"></igx-column>
</igx-column-group>
</igx-grid>
`
})
export class NumberColWidthGridComponent {
@ViewChild(IgxGridComponent, { read: IgxGridComponent })
grid: IgxGridComponent;

data = SampleTestData.contactInfoDataFull();

columns = [
{ field: 'ID', width: 100 },
{ field: 'CompanyName', width: 200 },
{ field: 'ContactName', width: 150 },
{ field: 'City', width: 100 },
];
}

function getColGroup(grid: IgxGridComponent, headerName: string): IgxColumnGroupComponent {
const colGroups = grid.columnList.filter(c => c.columnGroup && c.header === headerName);
if (colGroups.length === 0) {
Expand Down

0 comments on commit 8910806

Please sign in to comment.