This example will calculate a sum of values stored in a specified event field ("val"):
onBeforeCellRender: (args) => {
if (args.cell.isParent) {
const field = "val";
const children = dp.rows.find(args.cell.resource).children();
const sum = children.reduce((acc, row) => {
const events = row.events.forRange(args.cell.start, args.cell.end);
const total = events.reduce((acc, e) => acc + e.data[field], 0);
return acc + total;
}, 0);
args.cell.html = "" + sum;
}
}
The event data object would look like this:
const events = [
{
id: 1,
// ...
val: 3
},
{
id: 2,
// ...
val: 5
},
];