this.totalVacances = [{
columns: [
{
type: 'Custom',
field: 'arrayOfWeeks.week1.displayedText',
format: 'C2',
footerTemplate: 'Sum: ${Custom}',
customAggregate: this.customAggregateFnWeek1
},
{
type: 'Custom',
field: 'arrayOfWeeks.week2.displayedText',
format: 'C2',
footerTemplate: 'Average: ${Custom}',
customAggregate: this.customAggregateFnWeek2
} // AND SO ON... THESE ARE ONLY 2 WEEKS. IT COULD GO UP TO 52 weeks (but not always 52 weeks, it depends on the data supplied)
]
}];
for (let i = 1; i <= Object.keys(employee.arrayOfWeeks).length; i++) {// Dynamically create footer rows this.totalVacances[0]['columns'].push({}
type: 'Custom',
field: `arrayOfWeeks.week${i}.displayedText`,
format: 'C2',
footerTemplate: '${Custom}',
customAggregate: this.customAggregateFn
});
customAggregateFn(data, i): number {
let total = 0;
data.result.forEach(employee => {
if (employee['arrayOfWeeks']['week' + i]['cellClass'] === 'semaine1Vacances') {
total += 1;
}
});
return total;
}
|
App.component.ts
this.totalVacances[0]['columns'].push({
type: 'Custom',
field: `arrayOfWeeks.week${i}.displayedText`,
footerTemplate: '${Custom}',
customAggregate: this.customAggregateFn.bind(this, i)
}); |