Skip to content

Commit 531ebe3

Browse files
authored
Merge branch '9.1.x' into ddincheva/clipboardIE-9.1
2 parents eb5df17 + 0073c45 commit 531ebe3

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4934,14 +4934,14 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
49344934
let added = false;
49354935
let removed = false;
49364936

4937-
this.initColumns(this.columnList);
4938-
4939-
49404937
diff.forEachAddedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
49414938
this.onColumnInit.emit(record.item);
49424939
added = true;
4940+
record.item.pinned ? this._pinnedColumns.push(record.item) : this._unpinnedColumns.push(record.item);
49434941
});
49444942

4943+
this.initColumns(this.columnList);
4944+
49454945
diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent | IgxColumnGroupComponent>) => {
49464946
const isColumnGroup = record.item instanceof IgxColumnGroupComponent;
49474947
if (!isColumnGroup) {

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { IgxGridComponent } from './grid.component';
55
import { IgxGridModule } from './public_api';
66
import { GridTemplateStrings, ColumnDefinitions } from '../../test-utils/template-strings.spec';
77
import { SampleTestData } from '../../test-utils/sample-test-data.spec';
8-
import { ColumnHiddenFromMarkupComponent, ColumnCellFormatterComponent, DynamicColumnsComponent } from '../../test-utils/grid-samples.spec';
8+
import { ColumnHiddenFromMarkupComponent, ColumnCellFormatterComponent,
9+
DynamicColumnsComponent, GridAddColumnComponent } from '../../test-utils/grid-samples.spec';
910
import { configureTestSuite } from '../../test-utils/configure-suite';
1011
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
1112
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
@@ -27,7 +28,8 @@ describe('IgxGrid - Column properties #grid', () => {
2728
ColumnCellFormatterComponent,
2829
ColumnHaederClassesComponent,
2930
ColumnHiddenFromMarkupComponent,
30-
DynamicColumnsComponent
31+
DynamicColumnsComponent,
32+
GridAddColumnComponent
3133
],
3234
imports: [IgxGridModule, NoopAnimationsModule]
3335
})
@@ -167,6 +169,34 @@ describe('IgxGrid - Column properties #grid', () => {
167169
expect(grid.columnList.last.field).toMatch('Name');
168170
}));
169171

172+
it('should add new column at the correct visible index', fakeAsync(() => {
173+
const fix = TestBed.createComponent(GridAddColumnComponent);
174+
fix.detectChanges();
175+
const grid = fix.componentInstance.grid;
176+
const maxVindex = fix.componentInstance.columns.length - 1;
177+
178+
// add to unpinned area
179+
fix.componentInstance.columns.push({ field: 'City', width: 150, movable: true, type: 'string' });
180+
fix.detectChanges();
181+
182+
let cityCol = grid.getColumnByName('City');
183+
expect(cityCol.visibleIndex).toEqual(maxVindex + 1);
184+
185+
// remove the newly added column
186+
fix.componentInstance.columns.pop();
187+
fix.detectChanges();
188+
189+
cityCol = grid.getColumnByName('City');
190+
expect(cityCol).not.toBeDefined();
191+
192+
// add to pinned area
193+
fix.componentInstance.columns.push({ field: 'City', width: 150, movable: true, type: 'string', pinned: true });
194+
fix.detectChanges();
195+
196+
cityCol = grid.getColumnByName('City');
197+
expect(cityCol.visibleIndex).toEqual( 1);
198+
}));
199+
170200
it('should apply columnWidth on columns that don\'t have explicit width', () => {
171201
const fix = TestBed.createComponent(ColumnCellFormatterComponent);
172202
fix.componentInstance.grid.columnWidth = '200px';

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,33 @@ export class ColumnHiddenFromMarkupComponent extends BasicGridComponent {
121121
data = SampleTestData.personIDNameData();
122122
}
123123

124+
@Component({
125+
template: `
126+
<igx-grid #grid1 [data]="data" [columnPinning]='true' [width]="'900px'" [height]="'600px'">
127+
<igx-column *ngFor="let c of columns" [field]="c.field"
128+
[header]="c.field"
129+
[movable]="c.movable"
130+
[width]="c.width"
131+
[editable]="true"
132+
[pinned]="c.pinned"
133+
[dataType]="c.type">
134+
</igx-column>
135+
</igx-grid>
136+
`
137+
})
138+
export class GridAddColumnComponent extends BasicGridComponent implements OnInit {
139+
public columns: Array<any>;
140+
data = SampleTestData.contactInfoDataFull();
141+
public ngOnInit(): void {
142+
this.columns = [
143+
{ field: 'ID', width: 150, movable: true, type: 'string', pinned: true },
144+
{ field: 'CompanyName', width: 150, movable: true, type: 'string'},
145+
{ field: 'ContactName', width: 150, movable: true, type: 'string' },
146+
{ field: 'ContactTitle', width: 150, movable: true, type: 'string' },
147+
{ field: 'Address', width: 150, movable: true, type: 'string' }];
148+
}
149+
}
150+
124151
@Component({
125152
template: GridTemplateStrings.declareGrid('', '',
126153
ColumnDefinitions.idNameFormatter)

0 commit comments

Comments
 (0)