search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Summing cost values stored in "tags" (args.data.tags.cost)

Asked by Anonymous
12 hours ago.

Hello, is it possible to parse all events (regardless of the resource) within each day and summing costs values (stored e.g. in args.data.tags.cost) and display on a header row? I saw for hotel booking demo it is possible, but the capacity is stored with the resource. Many thanks in advance.

Answer posted by Dan Letecky [DayPilot]
11 hours ago.

Yes, you can do it using the onBeforeCellRender event, like this:

onBeforeCellRender: args => {
  if (args.cell.row.data && args.cell.row.data.frozen) {
    const events = scheduler.events.forRange(args.cell.start, args.cell.end);
    const total = events.reduce((sum, event) => sum + event.data.tags.cost), 0);
    args.cell.text = `$ ${total}`;
  }
}

The events.forRange() method finds all events in the specified date range. If you have events longer than one cell, they will be included in multiple columns.

The code above assumes that you have a frozen row at the top of the Scheduler dedicated for the totals:

const resources = [
  { name: "Total", id: "total", frozen: "top" },
  // ...
  // other resources
};
scheduler.update({resources});

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):