|
App.Component.html
<ejs-treegrid #treegrid [dataSource]='data' childMapping='subtasks' [treeColumnIndex]='0' [columns]="treegridColumns">
</ejs-treegrid>
<ng-template let-data #template1>
{{data.taskID + data.progress + data.duration}} //define the template column here
</ng-template>
App.component.ts
@ViewChild("template1")
public temp1: NgModel;
@ViewChild("treegrid")
public treegrid: TreeGrid;
public treegridColumns: any;
ngOnInit(): void {
this.data = sampleData;
}
ngAfterViewInit() {
this.treegridColumns = [
{
field: "taskID",
isPrimaryKey: "true",
headerText: "Task ID",
width: "90"
},
. . .
{ headerText: "taskName", width: "90", template: this.temp1 } //declare the template column here
];
}
|
|
App.Component.html:-
<ejs-treegrid #treegrid [dataSource] = 'data' childMapping = 'subtasks'[treeColumnIndex] = '0'[columns] = "treegridColumns"
(actionComplete) = 'actionComplete($event)'[editSettings] = 'editSettings'[toolbar] = 'toolbar' >
</ejs-treegrid >
App.Component.ts
export class AppComponent implements OnInit {
public data: Object[] = [];
public template: any;
public editSettings: Object;
public toolbar: string[];
@ViewChild("treegrid")
public treegrid: TreeGrid;
public treegridColumns: any;
ngOnInit(): void {
this.data = sampleData;
this.editSettings = {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: "Cell"
};
this.toolbar = ["Add", "Delete", "Update", "Cancel"];
}
actionComplete(args) {
if (args.type == "save") {
if (args.column.field == "progress" || args.column.field == "duration") {
var total = args.data.progress + args.data.duration;
this.treegrid.setCellValue(args.data.taskID, "Sum", total); //using setCellValue method update the calculative value to Sum column
}
}
}
|