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
1 month 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]
1 month 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});

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.