Skip to content

Commit 560f034

Browse files
MKirovaMKirova
authored andcommitted
feat(elements-grid): Add content children ready event.
1 parent 509f5a6 commit 560f034

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

projects/igniteui-angular-elements/src/app/custom-strategy.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,22 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
6666
(this as any).componentRef = {};
6767

6868
const toBeOrphanedChildren = Array.from(element.children).filter(x => !this._componentFactory.ngContentSelectors.some(sel => x.matches(sel)));
69+
const contentChildren = Array.from(element.children).filter(x => this._componentFactory.ngContentSelectors.some(sel => x.matches(sel)));
6970
for (const iterator of toBeOrphanedChildren) {
7071
// TODO: special registration OR config for custom
7172
}
73+
74+
const promises = [];
75+
for (const contentChild of contentChildren) {
76+
// these resolve after the parent, both the components needs to be initialized and the parent query schedule should complete before it is really ready.
77+
const child = contentChild as IgcNgElement;
78+
const promiseComponentReady = this.waitForCondition(() => (child.ngElementStrategy as any)?.componentRef && this.schedule.size == 0);
79+
promises.push(promiseComponentReady);
80+
}
81+
Promise.all(promises).then(() => {
82+
(this as any).componentRef?.instance.contentChildrenReady.emit();
83+
});
84+
7285
let parentInjector: Injector;
7386
let parentAnchor: ViewContainerRef;
7487
const parents: IgcNgElement[] = [];
@@ -211,6 +224,19 @@ class IgxCustomNgElementStrategy extends ComponentNgElementStrategy {
211224
}
212225
}
213226

227+
public waitForCondition(conditionFn: any, interval = 10) {
228+
return new Promise<void>((resolve) => {
229+
function checkCondition() {
230+
if (conditionFn()) {
231+
resolve();
232+
} else {
233+
setTimeout(checkCondition, interval);
234+
}
235+
}
236+
checkCondition();
237+
});
238+
}
239+
214240
public override setInputValue(property: string, value: any, transform?: (value: any) => any): void {
215241
if ((this as any).componentRef === null ||
216242
!(this as any).componentRef.instance) {

projects/igniteui-angular-elements/src/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ <h3 class="ig-typography__h6">Flat Grid (MRL column layout)</h3>
131131

132132
grid1.data = northwindProducts;
133133
grid2.data = northwindProducts;
134+
grid1.addEventListener('contentChildrenReady', () => {
135+
console.log("Ready!");
136+
restoreState();
137+
});
134138
const categories = Array.from(new Set(northwindProducts.map(x => x.CategoryName)));
135139

136140
let groupingExpression1 = [];
@@ -206,10 +210,7 @@ <h3 class="ig-typography__h6">Flat Grid (MRL column layout)</h3>
206210
document.getElementById("saveState").addEventListener("click", saveState);
207211
document.getElementById("restoreState").addEventListener("click", restoreState);
208212
document.getElementById("toggleIcon").addEventListener("click", toggleIcon);
209-
const stateComponent = document.getElementById('state');
210-
stateComponent.options = {
211-
paging: false
212-
};
213+
213214
});
214215

215216
buttonGroup.addEventListener("igcSelect", (e) => {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,14 @@ export abstract class IgxGridBaseDirective implements GridType,
10001000
@Output()
10011001
public selectedRowsChange = new EventEmitter<any[]>();
10021002

1003+
/* blazorInclude */
1004+
/** @hidden @internal */
1005+
/**
1006+
* Emitted when content children are attached and collections in grid are updated.
1007+
*/
1008+
@Output()
1009+
public contentChildrenReady = new EventEmitter<void>();
1010+
10031011
/**
10041012
* Emitted when the expanded state of a row gets changed.
10051013
*
@@ -4930,7 +4938,7 @@ export abstract class IgxGridBaseDirective implements GridType,
49304938
* @param value
49314939
* @param condition
49324940
* @param ignoreCase
4933-
* @deprecated in version 19.0.0.
4941+
* @deprecated in version 19.0.0.
49344942
*/
49354943
public filterGlobal(value: any, condition, ignoreCase?) {
49364944
this.filteringService.filterGlobal(value, condition, ignoreCase);

0 commit comments

Comments
 (0)