|
<ejs-treegrid #treegrid [dataSource]='data' idMapping='TaskID' parentIdMapping='parentID'
[treeColumnIndex]='1' (cellEdit)='cellEdit($event)' [columns]='columns'>
</ejs-treegrid>
ngOnInit(): void {
-----
this.columns = [
{
field: 'TaskID',
headerText: 'Task ID',
isPrimaryKey: true,
width: 90
},
{
field: 'Progress',
headerText: 'Progress Summed to parent',
type: 'number',
valueAccessor: this.totalChildProgress,
width: 100,
textAlign: 'Right'
}
---
];
}
totalChildProgress(field, data, column) {
if (!isNullOrUndefined(data.hasChildRecords)) {
//checking if the record has children
let totalUnitWeight = 0;
data.Children.map(row => {
//summing child value to show them in parent
totalUnitWeight += row['Progress'];
});
return totalUnitWeight;
}
return data.Progress;
}
|
|
[app.component.ts]
import { findChildrenRecords } from '@syncfusion/ej2-treegrid';
totalChildProgress(field, data, column) {
if (!isNullOrUndefined(data.hasChildRecords)) {
//checking if the record has children
let totalUnitWeight = 0;
//using findChildrenRecords method to get deep children records and calculate sum for it
findChildrenRecords(data).map(row => {
//summing child value to show them in parent
totalUnitWeight += row['Progress'];
});
return totalUnitWeight;
}
return data.Progress;
}
|