|
1 | 1 | import { async, TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing'; |
2 | 2 | import { IgxGridModule } from './grid.module'; |
3 | 3 | import { IgxGridComponent } from './grid.component'; |
4 | | -import { Component, ViewChild, DebugElement, OnInit, TemplateRef } from '@angular/core'; |
| 4 | +import { Component, ViewChild, DebugElement, OnInit, TemplateRef, ElementRef } from '@angular/core'; |
| 5 | + |
5 | 6 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
6 | 7 | import { IgxColumnComponent, IgxColumnGroupComponent } from '../column.component'; |
7 | 8 | import { SortingDirection } from '../../data-operations/sorting-expression.interface'; |
@@ -38,7 +39,8 @@ describe('IgxGrid - multi-column headers', () => { |
38 | 39 | NestedColumnGroupsGridComponent, |
39 | 40 | DynamicGridComponent, |
40 | 41 | NumberColWidthGridComponent, |
41 | | - NestedColGroupsWithTemplatesGridComponent |
| 42 | + NestedColGroupsWithTemplatesGridComponent, |
| 43 | + DynamicColGroupsGridComponent |
42 | 44 | ], |
43 | 45 | imports: [ |
44 | 46 | NoopAnimationsModule, |
@@ -1416,6 +1418,40 @@ describe('IgxGrid - multi-column headers', () => { |
1416 | 1418 | headerSpans = fixture.debugElement.queryAll(By.css('.' + GRID_COL_GROUP_THEAD_TITLE_CLASS)); |
1417 | 1419 | expect(headerSpans[1].nativeElement.textContent).toBe('Location'); |
1418 | 1420 | })); |
| 1421 | + |
| 1422 | + it('There shouldn\'t be any errors when dynamically removing a column group with filtering enabled', () => { |
| 1423 | + const fixture = TestBed.createComponent(DynamicColGroupsGridComponent); |
| 1424 | + fixture.detectChanges(); |
| 1425 | + |
| 1426 | + const grid = fixture.componentInstance.grid; |
| 1427 | + const button = fixture.componentInstance.removeBtn; |
| 1428 | + |
| 1429 | + let columnLength = grid.columnList.length; |
| 1430 | + let firstColumnGroup = grid.columnList.first; |
| 1431 | + let expectedColumnName = 'First'; |
| 1432 | + let expectedColumnListLength = 10; |
| 1433 | + |
| 1434 | + expect(firstColumnGroup.header).toEqual(expectedColumnName); |
| 1435 | + expect(expectedColumnListLength).toEqual(columnLength); |
| 1436 | + |
| 1437 | + expect(() => { |
| 1438 | + // Delete first column group |
| 1439 | + button.nativeElement.dispatchEvent(new Event('click')); |
| 1440 | + fixture.detectChanges(); |
| 1441 | + |
| 1442 | + // Delete first column group |
| 1443 | + button.nativeElement.dispatchEvent(new Event('click')); |
| 1444 | + fixture.detectChanges(); |
| 1445 | + }).not.toThrow(); |
| 1446 | + |
| 1447 | + firstColumnGroup = grid.columnList.first; |
| 1448 | + expectedColumnName = 'Third'; |
| 1449 | + columnLength = grid.columnList.length; |
| 1450 | + expectedColumnListLength = 3; |
| 1451 | + |
| 1452 | + expect(firstColumnGroup.header).toEqual(expectedColumnName); |
| 1453 | + expect(expectedColumnListLength).toEqual(columnLength); |
| 1454 | + }); |
1419 | 1455 | }); |
1420 | 1456 |
|
1421 | 1457 | @Component({ |
@@ -1766,6 +1802,54 @@ export class NestedColGroupsGridComponent { |
1766 | 1802 | data = SampleTestData.contactInfoDataFull(); |
1767 | 1803 | } |
1768 | 1804 |
|
| 1805 | +@Component({ |
| 1806 | + template: ` |
| 1807 | + <igx-grid [data]="data" [allowFiltering]="true"> |
| 1808 | + <igx-column-group *ngFor="let colGroup of columnGroups" [header]="colGroup.columnHeader"> |
| 1809 | + <igx-column *ngFor="let column of colGroup.columns" [field]="column.field" [dataType]="column.type" |
| 1810 | + [filterable]="true"></igx-column> |
| 1811 | + </igx-column-group> |
| 1812 | + </igx-grid> |
| 1813 | + <article> |
| 1814 | + <button #removeFirstColGroup (click)="removeFirstColumnGroup()">Remove first column group</button> |
| 1815 | + </article> |
| 1816 | + ` |
| 1817 | +}) |
| 1818 | +export class DynamicColGroupsGridComponent { |
| 1819 | + |
| 1820 | + @ViewChild(IgxGridComponent, { static: true }) |
| 1821 | + public grid: IgxGridComponent; |
| 1822 | + |
| 1823 | + @ViewChild('removeFirstColGroup', { static: true }) |
| 1824 | + public removeBtn: ElementRef; |
| 1825 | + |
| 1826 | + public columnGroups: Array<any>; |
| 1827 | + public data = SampleTestData.contactInfoDataFull(); |
| 1828 | + |
| 1829 | + constructor() { |
| 1830 | + this.columnGroups = [ |
| 1831 | + { columnHeader: 'First', columns: [ |
| 1832 | + { field: 'ID', type: 'string' }, |
| 1833 | + { field: 'CompanyName', type: 'string' }, |
| 1834 | + { field: 'ContactName', type: 'string' }, |
| 1835 | + ]}, |
| 1836 | + { columnHeader: 'Second', columns: [ |
| 1837 | + { field: 'ContactTitle', type: 'string' }, |
| 1838 | + { field: 'Address', type: 'string' }, |
| 1839 | + ]}, |
| 1840 | + { columnHeader: 'Third', columns: [ |
| 1841 | + { field: 'PostlCode', type: 'string' }, |
| 1842 | + { field: 'Contry', type: 'string' }, |
| 1843 | + ]}, |
| 1844 | + ]; |
| 1845 | + } |
| 1846 | + |
| 1847 | + public removeFirstColumnGroup() { |
| 1848 | + this.columnGroups = this.columnGroups.splice(1, this.columnGroups.length - 1); |
| 1849 | + } |
| 1850 | + |
| 1851 | +} |
| 1852 | + |
1769 | 1853 | @Component({ |
1770 | 1854 | template: ` |
1771 | 1855 | <igx-grid #grid [data]="data" height="600px" width="1000px" columnWidth="100px"> |
|
0 commit comments