|
<ejs-treegrid [dataSource]='data' height='240' [treeColumnIndex]='0' childMapping='children' >
<e-columns>
. . .
<e-column field='UnitWeight' headerText='Weight Per Unit' textAlign='Right' type='number' width=130></e-column>
<e-column field='TotalUnits' headerText='Total Units' textAlign='Right' type='number' width=125></e-column>
</e-columns>
<e-aggregates>
<e-aggregate [showChildSummary]='true'>
<e-columns>
<e-column field="UnitWeight" type="Sum">
<ng-template #footerTemplate let-data>Maximum: {{data.Sum}}</ng-template>
</e-column>
</e-columns>
</e-aggregate>
</e-aggregates>
</ejs-treegrid>` |
|
App.component.html
<ejs-treegrid [dataSource]='data' height='240' [treeColumnIndex]='0' childMapping='children' (actionComplete)="actionComplete($event)" >
<e-columns>
<e-column field="FreightID" isPrimaryKey="true" headerText="Freight ID" width="130" ></e-column>
. . .
</e-columns>
</ejs-treegrid>`
App.Component.ts
export class AppComponent {
public data: Object[] = [];
public editSettings: Object;
public treegrid: TreeGridComponent;
actionComplete(args) {
if (args.type == "save") {
this.treegrid.refresh(); //refresh the TreeGrid while on Editing
}
}
. . .
}
|
|
App.Component.html
<ejs-treegrid #treegrid [dataSource]="data" height="400" childMapping="children"
. . .
(actionComplete)="actionComplete($event)">
<e-columns>
<e-column field="FreightID" isPrimaryKey="true" headerText="Freight ID"
width="130"></e-column>
. . .
<e-column field="UnitWeight"
headerText="Weight Per Unit"
textAlign="Right"
type="number"
editType='numericedit'
[valueAccessor]='totalChildValue'
width="130"></e-column>
</e-columns>
</ejs-treegrid>
App.Component.ts
export class AppComponent {
public data: Object[] = [];
public editSettings: Object;
@ViewChild("treegrid")
public treegrid: TreeGridComponent;
actionComplete(args) {
if (args.type == "save") {
this.treegrid.refresh(); //refresh the TreeGrid upon saving
}
}
ngOnInit(): void {
this.data = summaryRowData;
totalChildValue(field, data, column) {
if (isNullOrUndefined(data.parentItem)) {
let totalUnitWeight = 0;
data.children.map(row => (totalUnitWeight += row["UnitWeight"])); //Sum the childvalues and update the parentrow Value
return totalUnitWeight;
}
return data.UnitWeight;
}
}
|