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

Displaying total hours when adding or editing shifts in daypilot scheduler control

Asked by Devendra
7 years ago.

Hi,

Is there any way or any property which will allow to display total number of hours vertically/horizontally? Is there any property exposed in Angular2 daypilot scheduler control?

Thanks,
Devendra.

Answer posted by Dan Letecky [DayPilot]
7 years ago.

The following tutorial (for AngularJS 1.x) shows how to display total time occupied by events in each row:
https://code.daypilot.org/54503/angularjs-timesheet-tutorial-javascript-php

You can use the same approach in Angular 2:

import {Component} from '@angular/core';
import {DayPilot} from "daypilot-pro-angular";

@Component({
  selector: 'angular2-scheduler-example',
  template: `<daypilot-scheduler [config]="config"></daypilot-scheduler`
})
export class AppComponent {

  config: any = {
    
    // ...
    rowHeaderColumns: [
        {title: "Date"},
        {title: "Total"}
    ],
    onBeforeRowHeaderRender: function(args) {
        var duration = args.row.events.totalDuration();
        if (duration.ticks > 0) {
            args.row.columns[0].html = duration.toString("h") + "h " + duration.toString("m") + "m";
        }
    }
  }
}

You can also display total time available by summing up the cell durations:

import {Component} from '@angular/core';
import {DayPilot} from "daypilot-pro-angular";

@Component({
  selector: 'angular2-scheduler-example',
  template: `<daypilot-scheduler [config]="config"></daypilot-scheduler`
})
export class AppComponent {

  config: any = {
    
    // ...
    rowHeaderColumns: [
        {title: "Date"},
        {title: "Total"}
    ],
    onBeforeRowHeaderRender: function(args) {
        var total = args.row.cells.all()
            .map(function(cell) { return cell.end.getTime() - cell.start.getTime(); })
            .reduce(function(total, duration) { return total + duration; }, 0);

        var duration = new DayPilot.Duration(total);

        if (duration.ticks > 0) {
            args.row.columns[0].html = duration.toString();
        }
    }
  }
}

Showing vertical summaries is not easy to implement at this moment.

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