Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,17 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U

for (let i = start; i < end && this.igxForOf[i] !== undefined; i++) {
const embView = this._embeddedViews.shift();
if (!embView.destroyed) {
if (embView && !embView.destroyed) {
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
|| embView.rootNodes[0].nextElementSibling);
const view = container.detach(0);

// embView and view both refer to the same collections
this.updateTemplateContext(embView.context, i);

// Because in Elements the whole parent div (containing data-index) gets removed (possibly due to being disconnected). In Angular it just gets moved.
// This ensures to update it with the new context and remove it first from DOM because of detach action before inserting it manually.
Comment thread
skrustev marked this conversation as resolved.
view.detectChanges();
Copy link
Copy Markdown
Member Author

@skrustev skrustev Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: In order to minimize this change since it is problematic so far only in Elements, this can be an option that can be enabled for the ForOf and be enabled only for the HGrid on Elements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO from a performance perspective this is fine, since this is only for small scrolls where a single view is moved and re-rendered. So an additional check should not cause a performance degradation.


container.insert(view);
Comment thread
skrustev marked this conversation as resolved.
this._embeddedViews.push(embView);
Comment thread
skrustev marked this conversation as resolved.
}
Expand All @@ -1081,12 +1086,15 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
const container = this.dc.instance._vcr as ViewContainerRef;
for (let i = prevIndex - 1; i >= this.state.startIndex && this.igxForOf[i] !== undefined; i--) {
const embView = this._embeddedViews.pop();
if (!embView.destroyed) {
if (embView && !embView.destroyed) {
this.scrollFocus(embView.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE)
|| embView.rootNodes[0].nextElementSibling);
// embView and view both refer to the same collections
const view = container.detach(container.length - 1);

this.updateTemplateContext(embView.context, i);
view.detectChanges();

container.insert(view, 0);
this._embeddedViews.unshift(embView);
Comment thread
skrustev marked this conversation as resolved.
}
Expand Down
Loading