|
<button ejs-button (click)="BtnClick($event)">Add Dashboard panel</button>
<!-- placing the custom component within ng-template -->
<ng-template #CustomTemplate>
<div style="height:100%; width: 100%;" class="templateContent">
<app-card></app-card>
</div>
</ng-template>
<!-- adding a ng container to append the template in the container -->
<ng-container #viewContainer></ng-container>
BtnClick(args) {
// adding panel dynamically
let panel: PanelModel[] = [{
id: "layout_" + this.count.toString(),
'sizeX': 2, 'sizeY': 2, 'row': 0, 'col': 0,
}];
this.Dashboard.addPanel(panel[0]);
//renders the (CustomTemplate) template in dom
const templateValue = this.CustomTemplate.createEmbeddedView(null);
// inserts the template into the view container
this.viewContainer.insert(templateValue);
// Obtaining the content element of the panel
let panel_Content = document.getElementById("layout_" + this.count.toString() + "_content");
// appending the template to the panel content element.
panel_Content.appendChild(templateValue.rootNodes[0]);
this.count= this.count+1;
} |
|
<button ejs-button (click)="BtnClick($event)">Update Dashboard panel</button>
BtnClick(args) {
// adding panel dynamically
let panel: PanelModel[] = [{
id: "layout_0" ,
'sizeX': 2, 'sizeY': 2, 'row': 0, 'col': 0,
}];
this.Dashboard.updatePanel(panel[0]);
//rendes the (CustomTemplate) temaplte in dom
const templateValue = this.CustomTemplate.createEmbeddedView(null);
// inserts the template into the view container
this.viewContainer.insert(templateValue);
// Obtaining the content element of the panel
let panel_Content = document.getElementById("layout_0_content");
// appending the template to the panel content element.
panel_Content.appendChild(templateValue.rootNodes[0]);
} |
|
UG Documentation |
|
|
Demo link |
|
|
API reference |
|
public appendComponent() {
const factory = this.cfResolver.resolveComponentFactory(MyDynamicComponent);
const componentRef = this.vcRef.createComponent<MyDynamicComponent>(
factory
);
componentRef.instance.message = "dynamic content";
// append the component to the corresponding panel
this.renderer.appendChild(
document.getElementById("layout_0_body"),
componentRef.injector.get(MyDynamicComponent).elRef.nativeElement
);
}
|
|
BtnClick() {
document.getElementById("layout_0_body").children[0].remove();
//rendes the (CustomTemplate) temaplte in dom
const templateValue = this.CustomTemplate.createEmbeddedView(null);
// inserts the template into the view container
this.viewContainer.insert(templateValue);
// Obtaining the content element of the panel
let panel_Content = document.getElementById("layout_0_body");
// appending the template to the panel content element.
panel_Content.appendChild(templateValue.rootNodes[0]);
this.count = this.count + 1;
} |