diff --git a/projects/igniteui-angular-elements/src/app/custom-strategy.ts b/projects/igniteui-angular-elements/src/app/custom-strategy.ts index 1907cba1fe7..9f889449920 100644 --- a/projects/igniteui-angular-elements/src/app/custom-strategy.ts +++ b/projects/igniteui-angular-elements/src/app/custom-strategy.ts @@ -77,6 +77,7 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy { // set componentRef to non-null to prevent DOM moves from re-initializing // TODO: Fail handling or cancellation needed? (this as any).componentRef = {}; + const contentChildrenTags = Array.from(element.children).filter(x => this._componentFactory.ngContentSelectors.some(sel => x.matches(sel))).map(x => x.tagName.toLocaleLowerCase()); // const toBeOrphanedChildren = Array.from(element.children).filter(x => !this._componentFactory.ngContentSelectors.some(sel => x.matches(sel))); // for (const iterator of toBeOrphanedChildren) { @@ -163,6 +164,15 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy { this.detectChanges(); + // check if there are any content children associated with a content query collection. + // if no, then just emit the event, otherwise we wait for the collection to be updated in updateQuery. + const contentChildrenTypes = this.config.filter(x => contentChildrenTags.indexOf(x.selector) !== -1).map(x => x.provideAs ?? x.component); + const contentQueryChildrenCollection = componentConfig.contentQueries.filter(x => contentChildrenTypes.includes(x.childType)); + if (contentQueryChildrenCollection.length === 0) { + // no content children, emit event immediately, since there's nothing to be attached. + (this as any).componentRef?.instance?.childrenAttached?.emit(); + } + if (parentAnchor && parentInjector) { // attempt to attach the newly created ViewRef to the parents's instead of the App global const parentViewRef = parentInjector.get(ViewContainerRef); @@ -328,6 +338,10 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy { list.reset(childRefs); list.notifyOnChanges(); } + if (this.schedule.size === 0) { + // children are attached and collections are updated, emit event. + (this as any).componentRef?.instance?.childrenAttached?.emit(); + } } private runQueryInDOM(element: HTMLElement, query: ContentQueryMeta): IgcNgElement[] { diff --git a/projects/igniteui-angular-elements/src/index.html b/projects/igniteui-angular-elements/src/index.html index 765bb001461..80b9214ded7 100644 --- a/projects/igniteui-angular-elements/src/index.html +++ b/projects/igniteui-angular-elements/src/index.html @@ -131,6 +131,10 @@

Flat Grid (MRL column layout)

grid1.data = northwindProducts; grid2.data = northwindProducts; + grid1.addEventListener('childrenAttached', () => { + console.log("Ready!"); + restoreState(); + }); const categories = Array.from(new Set(northwindProducts.map(x => x.CategoryName))); let groupingExpression1 = []; @@ -210,10 +214,7 @@

Flat Grid (MRL column layout)

document.getElementById("saveState").addEventListener("click", saveState); document.getElementById("restoreState").addEventListener("click", restoreState); document.getElementById("toggleIcon").addEventListener("click", toggleIcon); - const stateComponent = document.getElementById('state'); - stateComponent.options = { - paging: false - }; + }); buttonGroup.addEventListener("igcSelect", (e) => { @@ -290,7 +291,7 @@

Flat Grid (MRL column layout)

- + @@ -318,7 +319,12 @@

Flat Grid (MRL column layout)

+
+
+ + +
@@ -426,9 +432,27 @@

Flat Grid (MRL column layout)

import { html } from "/lit-html.js"; // jump around vite import analysis with dynamic import url const hgridData = (await import(`/assets/${'data'}/projects-hgrid.js`)).default; + function saveStateHierarchical() { + const stateComponent = document.getElementById('hgridState'); + const stringData = stateComponent.getStateAsString(); + window.localStorage.setItem(`hgrid1-state`, stringData); + } + + function restoreStateHierarchical() { + const stateComponent = document.getElementById('hgridState'); + const stateData = window.localStorage.getItem(`hgrid1-state`); + if (stateData) { + const obj = JSON.parse(stateData); + stateComponent.applyState(obj); + } + } let hgrid = document.getElementById('hgrid1'); + hgrid.addEventListener('childrenAttached', () => { + restoreStateHierarchical(); + }); hgrid.data = hgridData; - + document.getElementById("saveStateHierarchical").addEventListener("click", saveStateHierarchical); + document.getElementById("restoreStateHierarchical").addEventListener("click", restoreStateHierarchical); let developersRowIsland = document.getElementById('DevelopersRowIsland'); let virtualMachinesRowIsland = document.getElementById('VirtualMachinesRowIsland'); virtualMachinesRowIsland.paginatorTemplate = (ctx) => html` diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts b/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts index 5213151e54e..9cdd65fb949 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.directive.ts @@ -1041,6 +1041,14 @@ export abstract class IgxGridBaseDirective implements GridType, @Output() public selectedRowsChange = new EventEmitter(); + /* blazorInclude */ + /** @hidden @internal */ + /** + * Emitted when content children are attached and collections in grid are updated. + */ + @Output() + public childrenAttached = new EventEmitter(); + /** * Emitted when the expanded state of a row gets changed. *