Hello,
I didn't success to define a column template in a subgrid. I need to link to a template defined in HTML to bind click event to my component method. But when I define the template in my column, the grid display 'no dtata' instead of the desired rows.
Could you help me achieving the desired behavior please?
In my ts, I have something like:
And in my HTML:
Thanks,
Regards,
Matt
Hi Matthieu,
Thanks for contacting Syncfusion support.
Query: I need to link to a template defined in HTML to bind click event to my component method.
We have created a simple sample based on your requirement. Please find the below code example and sample for more information.
|
[app.component.html]
<ejs-grid #grid id="Grid" [dataSource]="parentData" [childGrid]="childGrid" [allowPaging]="true"> <e-columns> <e-column field="EmployeeID" headerText="Employee ID" width="120" textAlign="Right"></e-column> <e-column field="FirstName" headerText="Name" width="140"></e-column> <e-column field="Title" headerText="Title" width="170"></e-column> </e-columns> </ejs-grid>
<ng-template #childtemplate1 let-data> <div> <a rel='nofollow' href=“#” (click)="hyperclick($event)">{{data.ShipCity}}</a> </div> </ng-template> <ng-template #childtemplate2 let-data> <div> <a rel='nofollow' href=“#” (click)="hyperclick($event)">{{data.ShipName}}</a> </div> </ng-template>
[app.component.ts]
export class AppComponent { constructor( @Inject(ViewContainerRef) private viewContainerRef?: ViewContainerRef ) {} @ViewChild('grid', { static: true }) public grid: GridComponent; @ViewChild('childtemplate1', { static: true }) public childtemplate1: any; @ViewChild('childtemplate2', { static: true }) public childtemplate2: any; public parentData: Object[]; public childGrid: any; ngOnInit(): void { this.parentData = employeeData; this.childGrid = { dataSource: orderDatas, queryString: 'EmployeeID', allowPaging: true, pageSettings: { pageSize: 6, pageCount: 5 }, load: function() { this.registeredTemplate = {}; //set registertemplate value as empty in load event }, columns: [ { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120 }, { field: 'ShipCity', headerText: 'Ship City', template: this.childtemplate1, width: 120 }, { field: 'ShipName', headerText: 'Ship Name', template: this.childtemplate2, width: 150 } ] }; } ngAfterViewInit() { this.childtemplate1.elementRef.nativeElement._viewContainerRef = this.viewContainerRef; this.childtemplate2.elementRef.nativeElement._viewContainerRef = this.viewContainerRef; }
hyperclick(args) { console.log(this); console.log(args); } }
|
sample: https://stackblitz.com/edit/angular-vdcepu-dtkmsx?file=app.component.html,app.component.ts
Please get back to us if you need further assistance.
Regards,
Rajapandiyan S