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

Set Display to a Business Year in Scheduler

Asked by Nevski
6 months ago.

Is it possible to set a 'Business Year' in DayPilot?

I am looking at using the DayPilot Pro Scheduler for Javascript as an annual leave planner, but would only want to display the current year totals (ie 1st April to 31st March) but still allow booking past that date but not to show in row totals?

Is that possible please?

Answer posted by Dan Letecky [DayPilot]
6 months ago.

Yes, this is possible. You need to modify the row total calculation logic so that it only includes the selected events.

The Annual leave tutorial (https://code.daypilot.org/97780/php-annual-leave-scheduling-javascript-html5-frontend-mysql) calculates the row total from all events in a row:

onBeforeRowHeaderRender: function (args) {
  args.row.columns[0].html = "";
  var totalDuration = args.row.events.totalDuration();
  if (totalDuration.days() > 0) {
    args.row.columns[0].html = args.row.events.totalDuration().totalDays() + " days";
  }
},

You'll need to calculate the total manually for events from the selected range:

onBeforeRowHeaderRender: function (args) {
  args.row.columns[0].html = "";
  var totalDuration = args.row.events.forRange("2020-04-01", "2021-04-01")
    .map(function(e) { return e.duration(); })
    .reduce(function(previous, current) { return new DayPilot.Duration(previous.ticks + current.ticks); }, DayPilot.Duration.seconds(0));

  if (totalDuration.days() > 0) {
    args.row.columns[0].html = totalDuration.totalDays() + " days";
  }
},

You may want to further adjust the logic according to your needs.

Comment posted by Nevski
6 months ago.

Thank you.

I also calculated that if I use a start date I require, work out days in year and set that, and add Previous and Next buttons to change the year the numbers work as expected. Would this be correct? (Based on the API returning from StartDate and EndDate)

Just an alternative method.

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