Skip to content

Commit 7067fa9

Browse files
authored
Merge branch 'master' into ttonev-fix-10806
2 parents 9d398d9 + 87c5571 commit 7067fa9

File tree

6 files changed

+112
-30
lines changed

6 files changed

+112
-30
lines changed

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ export class GridBaseAPIService<T extends GridType> implements GridServiceType {
397397
if (args.cancel) {
398398
return;
399399
}
400+
401+
const isHierarchicalGrid = grid.nativeElement.tagName.toLowerCase() === 'igx-hierarchical-grid';
402+
403+
if (isHierarchicalGrid) {
404+
grid.hgridAPI.endEditAll();
405+
}
406+
400407
expandedStates.set(rowID, expanded);
401408
grid.expansionStates = expandedStates;
402409
this.crudService.endEdit(false);

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,23 @@ export interface IGridDataBindable {
5151
}
5252

5353
export interface CellType {
54-
value: any;
55-
editValue: any;
56-
selected: boolean;
57-
active: boolean;
58-
editable: boolean;
59-
editMode: boolean;
54+
value: any;
55+
editValue: any;
56+
selected: boolean;
57+
active: boolean;
58+
editable: boolean;
59+
editMode: boolean;
6060
nativeElement?: HTMLElement;
61-
column: ColumnType;
62-
row: RowType;
63-
grid: GridType;
64-
id: { rowID: any; columnID: number; rowIndex: number };
61+
column: ColumnType;
62+
row: RowType;
63+
grid: GridType;
64+
id: { rowID: any; columnID: number; rowIndex: number };
6565
cellID?: any;
6666
readonly?: boolean;
6767
title?: any;
68-
width: string;
68+
width: string;
6969
visibleColumnIndex?: number;
70-
update: (value: any) => void;
70+
update: (value: any) => void;
7171
setEditMode?(value: boolean): void;
7272
calculateSizeToFit?(range: any): number;
7373
activate?(event: FocusEvent | KeyboardEvent): void;
@@ -96,7 +96,7 @@ export interface RowType {
9696
children?: RowType[];
9797
parent?: RowType;
9898
hasChildren?: boolean;
99-
treeRow? : ITreeGridRecord;
99+
treeRow?: ITreeGridRecord;
100100
addRowUI?: boolean;
101101
focused?: boolean;
102102
grid: GridType;
@@ -246,6 +246,7 @@ export interface GridServiceType {
246246
getParentRowId?(child: GridType): any;
247247
getChildGrids?(inDepth?: boolean): GridType[];
248248
getChildGrid?(path: IPathSegment[]): GridType;
249+
endEditAll?(): void;
249250
// XXX: Fix type
250251
unsetChildRowIsland?(rowIsland: any): void;
251252
}

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-api.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { Subject } from 'rxjs';
33
import { GridType, IPathSegment } from '../common/grid.interface';
44
import { Injectable } from '@angular/core';
55
import { GridBaseAPIService } from '../api.service';
6-
76
@Injectable()
87
export class IgxHierarchicalGridAPIService extends GridBaseAPIService<GridType> {
98
protected childRowIslands: Map<string, IgxRowIslandComponent> = new Map<string, IgxRowIslandComponent>();
10-
protected childGrids: Map<string, Map<any, GridType>> =
9+
protected childGrids: Map<string, Map<any, GridType>> =
1110
new Map<string, Map<any, GridType>>();
1211

1312
public registerChildRowIsland(rowIsland: IgxRowIslandComponent) {
@@ -127,4 +126,16 @@ export class IgxHierarchicalGridAPIService extends GridBaseAPIService<GridType>
127126
const index = this.get_row_index_in_data(rowID, data);
128127
return data[index];
129128
}
129+
130+
public endEditAll(): void {
131+
const rootGrid = this.grid.rootGrid;
132+
if (rootGrid.gridAPI.crudService.cellInEditMode) {
133+
rootGrid.gridAPI.crudService.endEdit();
134+
}
135+
rootGrid.hgridAPI.getChildGrids(true).forEach(g => {
136+
if (g.gridAPI.crudService.cellInEditMode) {
137+
g.gridAPI.crudService.endEdit();
138+
}
139+
});
140+
}
130141
}

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,76 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
438438
expect(childGridSecondRow.inEditMode).toBeFalsy();
439439
});
440440

441+
it('should be able to prevent exiting of edit mode when row is toggled through the UI', async () => {
442+
hierarchicalGrid.primaryKey = 'ID';
443+
hierarchicalGrid.rowEditable = true;
444+
hierarchicalGrid.rowToggle.subscribe((e) => {
445+
e.cancel = true;
446+
});
447+
fixture.detectChanges();
448+
wait();
449+
450+
const masterGridFirstRow = hierarchicalGrid.hgridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
451+
expect(masterGridFirstRow.expanded).toBeFalsy();
452+
453+
const masterGridSecondCell = masterGridFirstRow.cells.find(c => c.columnIndex === 1);
454+
expect(masterGridSecondCell.editMode).toBeFalsy();
455+
456+
masterGridSecondCell.setEditMode(true);
457+
fixture.detectChanges();
458+
wait();
459+
460+
expect(masterGridSecondCell.editMode).toBeTruthy();
461+
462+
UIInteractions.simulateClickAndSelectEvent(masterGridFirstRow.expander);
463+
fixture.detectChanges();
464+
wait();
465+
466+
expect(masterGridFirstRow.expanded).toBeFalsy();
467+
expect(masterGridSecondCell.editMode).toBeTruthy();
468+
469+
hierarchicalGrid.rowToggle.subscribe((e) => {
470+
e.cancel = false;
471+
});
472+
UIInteractions.simulateClickAndSelectEvent(masterGridFirstRow.expander);
473+
fixture.detectChanges();
474+
wait();
475+
476+
expect(masterGridFirstRow.expanded).toBeTruthy();
477+
expect(masterGridSecondCell.editMode).toBeFalsy();
478+
479+
const childGrid = hierarchicalGrid.hgridAPI.getChildGrids(false)[0] as IgxHierarchicalGridComponent;
480+
expect(childGrid).toBeDefined();
481+
482+
childGrid.primaryKey = 'ID';
483+
childGrid.rowEditable = true;
484+
childGrid.rowToggle.subscribe((e) => {
485+
e.cancel = true;
486+
});
487+
fixture.detectChanges();
488+
wait();
489+
490+
childGrid.columnList.find(c => c.index === 1).editable = true;
491+
const childGridSecondRow = childGrid.gridAPI.get_row_by_index(1) as IgxHierarchicalRowComponent;
492+
expect(childGridSecondRow.expanded).toBeFalsy();
493+
494+
const childGridSecondCell = childGridSecondRow.cells.find(c => c.columnIndex === 1);
495+
expect(childGridSecondCell.editMode).toBeFalsy();
496+
497+
childGridSecondCell.setEditMode(true);
498+
fixture.detectChanges();
499+
wait();
500+
501+
expect(childGridSecondCell.editMode).toBeTruthy();
502+
503+
UIInteractions.simulateClickAndSelectEvent(childGridSecondRow.expander);
504+
fixture.detectChanges();
505+
wait();
506+
507+
expect(childGrid.gridAPI.crudService.cellInEditMode).toBeTruthy();
508+
expect(childGridSecondRow.inEditMode).toBeTruthy();
509+
});
510+
441511
it('child grid width should be recalculated if parent no longer shows scrollbar.', async () => {
442512
hierarchicalGrid.height = '1000px';
443513
fixture.detectChanges();

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class IgxHierarchicalRowComponent extends IgxRowDirective {
5858
}
5959

6060
public get viewIndex(): number {
61-
return this.index + (this.grid.paginator?.page || 0 ) * (this.grid.paginator?.perPage || 0);
61+
return this.index + (this.grid.paginator?.page || 0) * (this.grid.paginator?.perPage || 0);
6262
}
6363

6464
/**
@@ -80,7 +80,7 @@ export class IgxHierarchicalRowComponent extends IgxRowDirective {
8080
}
8181

8282
public get hasChildren() {
83-
return !!this.grid.childLayoutKeys.length;
83+
return !!this.grid.childLayoutKeys.length;
8484
}
8585

8686
/**
@@ -91,10 +91,10 @@ export class IgxHierarchicalRowComponent extends IgxRowDirective {
9191
return this.grid && this.grid.highlightedRowID === this.key;
9292
}
9393

94-
/**
95-
* @hidden
96-
*/
97-
public expanderClick(event) {
94+
/**
95+
* @hidden
96+
*/
97+
public expanderClick(event) {
9898
event.stopPropagation();
9999
this.toggle();
100100
}
@@ -109,7 +109,6 @@ export class IgxHierarchicalRowComponent extends IgxRowDirective {
109109
if (this.added) {
110110
return;
111111
}
112-
this.endEdit(this.grid.rootGrid);
113112
this.grid.gridAPI.set_row_expansion_state(this.key, !this.expanded);
114113
this.grid.cdr.detectChanges();
115114
}
@@ -150,13 +149,6 @@ export class IgxHierarchicalRowComponent extends IgxRowDirective {
150149

151150
// TODO: consider moving into CRUD
152151
protected endEdit(grid: GridType) {
153-
if (grid.gridAPI.crudService.cellInEditMode) {
154-
grid.gridAPI.crudService.endEdit();
155-
}
156-
grid.hgridAPI.getChildGrids(true).forEach(g => {
157-
if (g.gridAPI.crudService.cellInEditMode) {
158-
g.gridAPI.crudService.endEdit();
159-
}
160-
});
152+
grid.hgridAPI.endEditAll();
161153
}
162154
}

projects/igniteui-angular/src/public_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ export { IChipResourceStrings } from './lib/core/i18n/chip-resources';
136136
export { IActionStripResourceStrings } from './lib/core/i18n/action-strip-resources';
137137
export { PickerInteractionMode } from './lib/date-common/types';
138138
export { SplitterType } from './lib/splitter/splitter.component';
139+
export { GridSelectionRange } from './lib/grids/common/types';

0 commit comments

Comments
 (0)