Skip to content

Commit

Permalink
feat(datagrid): reuse embedded view in *clrIfDetail directive
Browse files Browse the repository at this point in the history
Reusing DOM elements and component instance is more preformant. This
also fixes column width calculation issues if there is a datagrid inside
a datagrid detail panel.
  • Loading branch information
kevinbuhmann committed Oct 11, 2022
1 parent df7dcc2 commit 3aaaa49
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions projects/angular/src/data/datagrid/datagrid-if-detail.ts
Expand Up @@ -6,6 +6,7 @@

import {
Directive,
EmbeddedViewRef,
EventEmitter,
Input,
OnDestroy,
Expand All @@ -24,6 +25,7 @@ import { DetailService } from './providers/detail.service';
export class ClrIfDetail implements OnInit, OnDestroy {
private subscriptions: Subscription[] = [];
private skip = false; // This keeps us from resetting the input and calling the toggle twice
private embeddedViewRef: EmbeddedViewRef<any>;

@Input('clrIfDetail')
set state(model: any) {
Expand Down Expand Up @@ -57,11 +59,21 @@ export class ClrIfDetail implements OnInit, OnDestroy {

private togglePanel(showPanel: boolean) {
let stateChangeParams = null;
this.viewContainer.clear();

if (showPanel === true) {
this.viewContainer.createEmbeddedView(this.templateRef, { $implicit: this.detailService.state });
const embeddedViewContext = { $implicit: this.detailService.state };

if (this.embeddedViewRef) {
this.embeddedViewRef.context = embeddedViewContext;
} else {
this.embeddedViewRef = this.viewContainer.createEmbeddedView(this.templateRef, embeddedViewContext);
}

this.skip = true;
stateChangeParams = this.detailService.state;
} else {
this.viewContainer.clear();
this.embeddedViewRef = null;
}

this.stateChange.emit(stateChangeParams);
Expand Down

0 comments on commit 3aaaa49

Please sign in to comment.