[app.component.html]
<ej-gantt id="GanttControl" [dataSource]="ganttData" (actionComplete)="actionComplete($event)"
(queryCellInfo) = "queryCellInfo($event)" >
//...
</ej-gantt>
[app.component.ts]
export class AppComponent {
public totalRecords: any = [];
constructor() {
//...
queryCellInfo(args) {
if ((args.column.field == "Totalvalue") && args.data.hasChildRecords == true) {
var records = this.getChildRecords(args.data, args.model.updatedRecords);
var updated_value = ej.sum(records, "Totalvalue");
args.cellValue = updated_value;
$(args.cellElement).text(updated_value);
this.totalRecords = [];
}
}
actionComplete(args) {
if (args.requestType == "recordUpdate") {
this.update(args.data.parentItem);
}
if (args.requestType == "save" && args.addedRecord) {
this.update(args.addedRecord.parentItem);
}
if (args.requestType == "delete") {
this.update(args.data.parentItem);
}
}
public getChildRecords(parentRecord, updatedRecords): any {
var recordLength = updatedRecords.length, record;
for (var length = 0; length < recordLength; length++) {
record = updatedRecords[length];
if (parentRecord == record.parentItem) {
if (record.hasChildRecords)
this.getChildRecords(record, updatedRecords);
else
this.totalRecords.push(record);
}
}
return this.totalRecords;
}
public update(parentItem) {
var totValue = 0;
if (parentItem != null) {
let childRecords = parentItem.childRecords,
len = childRecords.length;
for (var i = 0; i < len; i++) {
var totalvalue = parentItem.childRecords[i].Totalvalue;
if (totalvalue)
totValue = totValue + totalvalue;
parentItem.Totalvalue = totValue;
}
let proxy = $('#GanttControl').ejGantt('instance');
let treeGridObj = proxy._$treegridHelper.data("ejTreeGrid");
treeGridObj.refreshRow(treeGridObj.model.updatedRecords.indexOf(parentItem));
return this.update(parentItem.parentItem);
}
}
}
|