Skip to content

Commit 38eb369

Browse files
committed
fix(hgrid): add and use lifecycle placeholder for grid connection events.
1 parent 19b6865 commit 38eb369

3 files changed

Lines changed: 58 additions & 13 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,8 @@
276276
<ng-content select="igx-column,igc-column,igx-column-group,igc-column-group,igx-action-strip,igc-action-strip"></ng-content>
277277
<ng-content select="igx-row-island,igc-row-island"></ng-content>
278278
}
279+
280+
<!-- Lifecycle placeholder used to determine when the grid gets connected/disconnected from the DOM, for example as a result of virtualization or caching. -->
281+
<igc-hgrid-lifecycle-placeholder (igcConnected)="onLifecyclePlaceholderConnected()"
282+
(igcDisconnected)="onLifecyclePlaceholderDisconnected()">
283+
</igc-hgrid-lifecycle-placeholder>

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

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { IgxPaginatorToken } from 'igniteui-angular/paginator';
3838
import { IgxGridCellMergePipe, IgxGridComponent, IgxGridFilteringPipe, IgxGridSortingPipe, IgxGridUnmergeActivePipe } from 'igniteui-angular/grids/grid';
3939

4040
let NEXT_ID = 0;
41+
const HGRID_LIFECYCLE_PLACEHOLDER_TAG = 'igc-hgrid-lifecycle-placeholder';
4142

4243
/**
4344
* @hidden @internal
@@ -662,6 +663,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
662663
* @hidden
663664
*/
664665
public override ngOnInit() {
666+
this.registerLifecyclePlaceholderElement();
665667
// this.expansionStatesChange.pipe(takeUntil(this.destroy$)).subscribe((value: Map<any, boolean>) => {
666668
// const res = Array.from(value.entries()).filter(({1: v}) => v === true).map(([k]) => k);
667669
// });
@@ -674,6 +676,26 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
674676
super.ngOnInit();
675677
}
676678

679+
// Event that triggers when element gets connected back to the DOM.
680+
// Used to determine when to reopen a previously closed row editing overlay.
681+
protected onLifecyclePlaceholderConnected(): void {
682+
if (this.rowEditable && this.crudService.rowInEditMode && this.rowEditingOverlay &&
683+
this.rowEditingOverlay.collapsed) {
684+
// Row is in edit mode, but overlay is closed - reopen.
685+
this.openRowOverlay(this.crudService.rowInEditMode.id);
686+
}
687+
688+
}
689+
690+
// Event that triggers when element gets disconnected from the DOM, for example as a result of virtualization or caching.
691+
// Used to determine when to close the row editing overlay.
692+
protected onLifecyclePlaceholderDisconnected(): void {
693+
if (this.rowEditable && this.crudService.rowInEditMode && this.rowEditingOverlay) {
694+
// disconnected from DOM (possibly cached) & row was in edit mode - close overlay.
695+
this.closeRowEditingOverlay();
696+
}
697+
}
698+
677699
/**
678700
* @hidden
679701
*/
@@ -720,6 +742,24 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
720742
this.parentIsland.showExpandAll : this.rootGrid.showExpandAll;
721743
}
722744

745+
private registerLifecyclePlaceholderElement(): void {
746+
if (!this.platform.isBrowser || typeof customElements === 'undefined' || customElements.get(HGRID_LIFECYCLE_PLACEHOLDER_TAG)) {
747+
return;
748+
}
749+
750+
class IgxHierarchicalGridLifecyclePlaceholderElement extends HTMLElement {
751+
public connectedCallback(): void {
752+
this.dispatchEvent(new CustomEvent('igcConnected', { bubbles: true, composed: true }));
753+
}
754+
755+
public disconnectedCallback(): void {
756+
this.dispatchEvent(new CustomEvent('igcDisconnected', { bubbles: true, composed: true }));
757+
}
758+
}
759+
760+
customElements.define(HGRID_LIFECYCLE_PLACEHOLDER_TAG, IgxHierarchicalGridLifecyclePlaceholderElement);
761+
}
762+
723763
/**
724764
* @hidden
725765
*/
@@ -1232,15 +1272,15 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
12321272
{
12331273
name: null,
12341274
fields: filterableFields.map(f => ({
1235-
field: f.field,
1236-
dataType: f.dataType,
1237-
header: f.header,
1238-
editorOptions: f.editorOptions,
1239-
filters: f.filters,
1240-
pipeArgs: f.pipeArgs,
1241-
defaultTimeFormat: f.defaultTimeFormat,
1242-
defaultDateTimeFormat: f.defaultDateTimeFormat
1243-
})) as FieldType[]
1275+
field: f.field,
1276+
dataType: f.dataType,
1277+
header: f.header,
1278+
editorOptions: f.editorOptions,
1279+
filters: f.filters,
1280+
pipeArgs: f.pipeArgs,
1281+
defaultTimeFormat: f.defaultTimeFormat,
1282+
defaultDateTimeFormat: f.defaultDateTimeFormat
1283+
})) as FieldType[]
12441284
}
12451285
];
12461286

@@ -1249,7 +1289,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
12491289
this.data[0][rowIsland.key][0] : null;
12501290
return acc.concat(this.generateChildEntity(rowIsland, childFirstRowData));
12511291
}
1252-
, []);
1292+
, []);
12531293
}
12541294

12551295
return entities;

src/app/hierarchical-grid/hierarchical-grid.sample.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ <h4 class="sample-title">Sample two</h4>
146146
<igx-grid-toolbar-exporter></igx-grid-toolbar-exporter>
147147
</igx-grid-toolbar-actions>
148148
</igx-grid-toolbar>
149-
<igx-row-island [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true" [rowEditable]="true"
149+
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true" [rowEditable]="true"
150150
[allowFiltering]="true">
151-
<igx-row-island [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true" [rowEditable]="true"
151+
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData'" [autoGenerate]="true" [rowSelection]='selectionMode' [batchEditing]="true" [rowEditable]="true"
152152
[allowFiltering]="true"></igx-row-island>
153153
</igx-row-island>
154-
<igx-row-island [key]="'childData2'" [autoGenerate]="true" [allowFiltering]="true"></igx-row-island>
154+
<igx-row-island [rowEditable]="true" [primaryKey]="'ID'" [key]="'childData2'" [autoGenerate]="true" [allowFiltering]="true"></igx-row-island>
155155
</igx-hierarchical-grid>
156156

157157

0 commit comments

Comments
 (0)