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

Is there a way to display total quantities from events in the Scheduler Scale header, aggregated both weekly and monthly

Asked by Iliah
29 days ago.

Is there a way to display total quantities from events in the Scheduler Scale header, aggregated both weekly and monthly

BRG
Iliah

Comment posted by Iliah
29 days ago.

added picture

Answer posted by Dan Letecky [DayPilot]
29 days ago.

Yes, you can use the onBeforeTimeHeaderRender event handler to customize the time header.

There is a tutorial available that shows how to calculate the summary/utilization details using methods like events.forRange(). This project displays the totals in a special frozen row but you can use the same approach with the time header.

Comment posted by Iliah
29 days ago.

Thanks for the helpful explanation.
How can I determine whether the onBeforeTimeHeaderRender event is triggered for a weekly or monthly header cell? I need to apply different calculations depending on the time scale level?

Comment posted by Dan Letecky [DayPilot]
29 days ago.

The args.header.level property stores the row number (starting at 0 for the first row from the top).

You can also use args.header.start and args.header.end to get the duration:

const duration = new DayPilot.Duration(args.header.start, args.header.end);
const days = duration.totalDays();
Comment posted by Iliah
28 days ago.

:)

onBeforeTimeHeaderRender: (args) => {
  if (!scheduler.events.list) {
    console.log('scheduler.events.list is undefined');
    return;
  }

  if (scheduler.events.list.length === 0) {
    console.log('scheduler.events.list.length = 0');
    return;
  }

  if (args.header.level === 0 || args.header.level === 1) {
    const events = scheduler.events.forRange(args.header.start, args.header.end);
    const sum = events.reduce((acc, event) => acc + event.data.quantity, 0);
    args.header.html = `${args.header.text} ( ${sum.toString()} )`;
  }
}
Comment posted by Dan Letecky [DayPilot]
28 days ago.

Thanks for posting your solution!

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