Sorry for the delay.
I would make a few changes:
-
Instead of using a special time header row, use a frozen row.
-
Mark this row with cellsAutoUpdated: true, that will re-render the content on every change (events loaded, event moved or created…).
-
Use onBeforeCellRender to calculate and display the column total (there is no need to pre-calculate it).
The key elements could look like this:
A. When loading resources, prepend the frozen row with the totals
async loadResources() {
const {data} = await DayPilot.Http.get("/resources/");
const resources = [
{name: "Totals", id: "totals", frozen: "top", cellsAutoUpdated: true},
...data
];
dp.update({resources});
}
B. Calculate the totals:
const scheduler = new DayPilot.Scheduler("scheduler", {
onBeforeCellRender: args => {
if (args.cell.resource === "totals") {
const events = scheduler.events.forRange(args.cell.start, args.cell.end);
const total = events.reduce((sum, e) => {
const weight = e.data?.tags?.weight ?? 0;
return sum + (Number.isFinite(n) ? n : 0);
}, 0);
args.cell.properties.text = total;
}
},
// ..
});
// ...
You can also take a look at the following tutorial which implements a simplified version of this logic (it just counts the events):
Let me know if it doesn’t work as expected.