Skip to content

Commit f3c2e08

Browse files
authored
Merge pull request #9995 from IgniteUI/pbozhinov/fix-9925
Enable row editing overlay customization for child-level records
2 parents 6a49946 + b25c4dc commit f3c2e08

File tree

4 files changed

+137
-10
lines changed

4 files changed

+137
-10
lines changed

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,14 +1123,14 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
11231123
/**
11241124
* @hidden @internal
11251125
*/
1126-
@ContentChild(IgxRowEditTemplateDirective, { read: TemplateRef })
1127-
public rowEditCustom: TemplateRef<any>;
1126+
@ContentChildren(IgxRowEditTemplateDirective, { descendants: false, read: TemplateRef })
1127+
public rowEditCustomDirectives: QueryList<TemplateRef<any>>;
11281128

11291129
/**
11301130
* @hidden @internal
11311131
*/
1132-
@ContentChild(IgxRowEditTextDirective, { read: TemplateRef })
1133-
public rowEditText: TemplateRef<any>;
1132+
@ContentChildren(IgxRowEditTextDirective, { descendants: false, read: TemplateRef })
1133+
public rowEditTextDirectives: QueryList<TemplateRef<any>>;
11341134

11351135
/**
11361136
* @hidden @internal
@@ -1141,8 +1141,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
11411141
/**
11421142
* @hidden @internal
11431143
*/
1144-
@ContentChild(IgxRowEditActionsDirective, { read: TemplateRef })
1145-
public rowEditActions: TemplateRef<any>;
1144+
@ContentChildren(IgxRowEditActionsDirective, { descendants: false, read: TemplateRef })
1145+
public rowEditActionsDirectives: QueryList<TemplateRef<any>>;
11461146

11471147

11481148
/**
@@ -2197,6 +2197,36 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
21972197
return this.outlet;
21982198
}
21992199

2200+
/**
2201+
* @hidden @internal
2202+
*/
2203+
public get rowEditCustom(): TemplateRef<any> {
2204+
if (this.rowEditCustomDirectives && this.rowEditCustomDirectives.first) {
2205+
return this.rowEditCustomDirectives.first;
2206+
}
2207+
return null;
2208+
}
2209+
2210+
/**
2211+
* @hidden @internal
2212+
*/
2213+
public get rowEditText(): TemplateRef<any> {
2214+
if (this.rowEditTextDirectives && this.rowEditTextDirectives.first) {
2215+
return this.rowEditTextDirectives.first;
2216+
}
2217+
return null;
2218+
}
2219+
2220+
/**
2221+
* @hidden @internal
2222+
*/
2223+
public get rowEditActions(): TemplateRef<any> {
2224+
if (this.rowEditActionsDirectives && this.rowEditActionsDirectives.first) {
2225+
return this.rowEditActionsDirectives.first;
2226+
}
2227+
return null;
2228+
}
2229+
22002230
/**
22012231
* @hidden @internal
22022232
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
<div *ngIf="rowEditable" igxToggle #rowEditingOverlay>
185185
<div [className]="bannerClass">
186186
<ng-container
187-
*ngTemplateOutlet="rowEditContainer; context: { rowChangesCount: rowChangesCount, endEdit: this.crudService.endEdit.bind(this) }">
187+
*ngTemplateOutlet="resolveRowEditContainer; context: { rowChangesCount: rowChangesCount, endEdit: this.crudService.endEdit.bind(this) }">
188188
</ng-container>
189189
</div>
190190
</div>
@@ -199,15 +199,15 @@
199199
<div class="igx-banner__message">
200200
<span class="igx-banner__text">
201201
<ng-container
202-
*ngTemplateOutlet="this.crudService.row?.getClassName() === 'IgxAddRow' ? rowAddText : rowEditText ? rowEditText : defaultRowEditText;
202+
*ngTemplateOutlet="this.crudService.row?.getClassName() === 'IgxAddRow' ? rowAddText : resolveRowEditText || defaultRowEditText;
203203
context: { $implicit: this.crudService.row?.getClassName() !== 'IgxAddRow' ? rowChangesCount : null }">
204204
</ng-container>
205205
</span>
206206
</div>
207207
<div class="igx-banner__actions">
208208
<div class="igx-banner__row">
209209
<ng-container
210-
*ngTemplateOutlet="rowEditActions ? rowEditActions : defaultRowEditActions; context: { $implicit: this.endEdit.bind(this) }">
210+
*ngTemplateOutlet="resolveRowEditActions || defaultRowEditActions; context: { $implicit: this.endEdit.bind(this) }">
211211
</ng-container>
212212
</div>
213213
</div>

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,30 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
328328
return !!this.childLayoutKeys.length;
329329
}
330330

331+
/**
332+
* @hidden
333+
*/
334+
public get resolveRowEditContainer() {
335+
if (this.parentIsland && this.parentIsland.rowEditCustom) {
336+
return this.parentIsland.rowEditContainer;
337+
}
338+
return this.rowEditContainer;
339+
}
340+
341+
/**
342+
* @hidden
343+
*/
344+
public get resolveRowEditActions() {
345+
return this.parentIsland ? this.parentIsland.rowEditActions : this.rowEditActions;
346+
}
347+
348+
/**
349+
* @hidden
350+
*/
351+
public get resolveRowEditText() {
352+
return this.parentIsland ? this.parentIsland.rowEditText : this.rowEditText;
353+
}
354+
331355
/** @hidden */
332356
public hideActionStrip() {
333357
if (!this.parent) {

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

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,8 @@ describe('IgxHierarchicalGrid Runtime Row Island change Scenarios #hGrid', () =>
13221322
configureTestSuite((() => {
13231323
TestBed.configureTestingModule({
13241324
declarations: [
1325-
IgxHierarchicalGridToggleRIComponent
1325+
IgxHierarchicalGridToggleRIComponent,
1326+
IgxHierarchicalGridCustomRowEditOverlayComponent
13261327
],
13271328
imports: [
13281329
NoopAnimationsModule, IgxHierarchicalGridModule]
@@ -1405,6 +1406,55 @@ describe('IgxHierarchicalGrid Runtime Row Island change Scenarios #hGrid', () =>
14051406

14061407
});
14071408

1409+
it(`Should apply template to both parent and child grids`, async () => {
1410+
const customFixture = TestBed.createComponent(IgxHierarchicalGridCustomRowEditOverlayComponent);
1411+
customFixture.detectChanges();
1412+
hierarchicalGrid = customFixture.componentInstance.hgrid;
1413+
hierarchicalGrid.primaryKey = 'ID';
1414+
hierarchicalGrid.rowEditable = true;
1415+
1416+
let cellElem = hierarchicalGrid.hgridAPI.get_cell_by_index(0, 'ProductName');
1417+
let row = hierarchicalGrid.gridAPI.get_row_by_index(0);
1418+
1419+
UIInteractions.simulateDoubleClickAndSelectEvent(cellElem);
1420+
customFixture.detectChanges();
1421+
expect(row.inEditMode).toBe(true);
1422+
1423+
const mainGridOverlay = GridFunctions.getRowEditingOverlay(customFixture);
1424+
expect(mainGridOverlay).not.toBeNull();
1425+
1426+
const mainGridOverlayTextContent = mainGridOverlay.querySelector('.igx-banner__text').textContent;
1427+
const mainGridOverlayActionsContent = mainGridOverlay.querySelector('.igx-banner__actions').textContent;
1428+
1429+
expect(mainGridOverlayTextContent).toBe(' You have 0 changes in this row\n');
1430+
expect(mainGridOverlayActionsContent).toBe('CancelDone');
1431+
1432+
hierarchicalGrid.expandRow(hierarchicalGrid.getRowByIndex(0).rowID);
1433+
customFixture.detectChanges();
1434+
1435+
const secondLevelGrid = hierarchicalGrid.hgridAPI.getChildGrids()[0];
1436+
expect(secondLevelGrid).not.toBeNull();
1437+
customFixture.detectChanges();
1438+
1439+
expect(GridFunctions.getRowEditingOverlay(customFixture)).toBeNull();
1440+
1441+
cellElem = secondLevelGrid.hgridAPI.get_cell_by_index(0, 'ProductName');
1442+
row = secondLevelGrid.gridAPI.get_row_by_index(0);
1443+
1444+
UIInteractions.simulateDoubleClickAndSelectEvent(cellElem);
1445+
customFixture.detectChanges();
1446+
expect(row.inEditMode).toBe(true);
1447+
1448+
const nestedGridOverlay = GridFunctions.getRowEditingOverlay(customFixture);
1449+
expect(nestedGridOverlay).not.toBeNull();
1450+
1451+
const nestedGridOverlayTextContent = nestedGridOverlay.querySelector('.igx-banner__text').textContent;
1452+
const nestedGridOverlayActionsContent = nestedGridOverlay.querySelector('.igx-banner__actions').textContent;
1453+
1454+
expect(nestedGridOverlayTextContent).toBe('Row Edit Text');
1455+
expect(nestedGridOverlayActionsContent).toBe('Row Edit Actions');
1456+
});
1457+
14081458
it(`Should keep the overlay when scrolling an igxHierarchicalGrid with an opened
14091459
row island with <= 2 data records`, async () => {
14101460
hierarchicalGrid.primaryKey = 'ID';
@@ -1845,3 +1895,26 @@ export class IgxHierarchicalGridHidingPinningColumnsComponent extends IgxHierarc
18451895
col.hidden = true;
18461896
}
18471897
}
1898+
1899+
@Component({
1900+
template: `
1901+
<igx-hierarchical-grid #grid1 [data]="data" [autoGenerate]="false"
1902+
[height]="'400px'" [width]="width" [rowEditable]="true" #hierarchicalGrid>
1903+
<igx-column field="ID"></igx-column>
1904+
<igx-column field="ProductName"></igx-column>
1905+
<igx-row-island [key]="'childData'" [autoGenerate]="false" [rowEditable]="true"
1906+
#rowIsland>
1907+
<igx-column field="ID"></igx-column>
1908+
<igx-column field="ProductName"></igx-column>
1909+
<igx-row-island [key]="'childData'" [autoGenerate]="true" #rowIsland2 >
1910+
</igx-row-island>
1911+
<ng-template igxRowEditText let-rowChangesCount>
1912+
<span>Row Edit Text</span>
1913+
</ng-template>
1914+
<ng-template igxRowEditActions let-endRowEdit>
1915+
<span>Row Edit Actions</span>
1916+
</ng-template>
1917+
</igx-row-island>
1918+
</igx-hierarchical-grid>`
1919+
})
1920+
export class IgxHierarchicalGridCustomRowEditOverlayComponent extends IgxHierarchicalGridTestBaseComponent { }

0 commit comments

Comments
 (0)