Features

  • A weekly Angular timetable component based on the Angular Calendar component from DayPilot Pro for JavaScript.
  • Seven lesson periods with real start and end times, including different durations. Breaks and lunch take no grid space.
  • Custom period labels, event colors, lesson creation, moving and resizing.
  • Includes a trial version of DayPilot Pro for JavaScript (see License below).

License

Licensed for testing and evaluation purposes. Please see the license agreement included in the sample project. You can use the source code of the tutorial if you are a licensed user of DayPilot Pro for JavaScript.

Angular Timetable Based on a Weekly Calendar

angular timetable week

We will start with a new Angular project generated using Calendar UI Builder. The sample uses a standalone component and Angular signals: config holds Calendar options and events holds lesson data.

The Calendar displays one column for each school day. Set viewType to "WorkWeek" and weekStarts to 1 for Monday–Friday. The displayed week starts on the current Monday, and the sample data uses that same date. Previous week, This week and Next week buttons change the visible week.

A manual, non-continuous timeline lets each row represent an actual lesson period. It requires DayPilot Pro for JavaScript 2026.4.7150 or later, including its Angular package.

config = signal<DayPilot.CalendarConfig>({
  startDate: this.week(),
  viewType: "WorkWeek",
  weekStarts: 1,
  scale: "Manual",
  timeline: this.timeline(this.week()),
  heightSpec: "Full",
  // ...
});
<daypilot-calendar [config]="config" [events]="events" #calendar></daypilot-calendar>

Lesson Periods and Hidden Breaks

angular timetable periods

Define all seven periods in one typed array. Each item contains its name and real start/end time; there is no artificial hour-to-block conversion. The periods below last 45, 60 or 75 minutes. Gaps between them represent ordinary breaks and lunch.

src/app/calendar/periods.ts

import {DayPilot} from "daypilot-pro-angular";

export interface LessonPeriod {
  name: string;
  start: string;
  end: string;
}

export const periods: LessonPeriod[] = [
  {name: "Period 1", start: "08:15", end: "09:00"},
  {name: "Period 2", start: "09:10", end: "10:10"},
  {name: "Period 3", start: "10:30", end: "11:15"},
  {name: "Period 4", start: "11:25", end: "12:40"},
  {name: "Period 5", start: "13:30", end: "14:15"},
  {name: "Period 6", start: "14:25", end: "15:25"},
  {name: "Period 7", start: "15:35", end: "16:20"}
];

Build one timeline cell for each period. The at() helper combines a date with a time. The reference date supplies the daily pattern; WorkWeek repeats that pattern across all five columns.

export function at(day: DayPilot.Date, time: string): DayPilot.Date {
  return new DayPilot.Date(`${day.toString("yyyy-MM-dd")}T${time}:00`);
}
timeline(day: DayPilot.Date): NonNullable<DayPilot.CalendarConfig["timeline"]> {
    return periods.map(period => ({
      start: at(day, period.start),
      end: at(day, period.end),
      height: 60
    }));
  }

The default height is 60 pixels for every period, so long and short lessons have equal visual weight. heightSpec: "Full" shows all seven rows. Do not add timeline cells for breaks: the 12:40–13:30 lunch interval, for example, consumes no vertical space. The sample hides the horizontal break markers so the period rows form a clean grid.

Use onBeforeGridLineRender to hide the special horizontal lines at omitted time intervals. Setting args.hidden for "HorizontalBreak" removes the break markers without changing the timeline or lesson boundaries. The regular cell borders remain visible.

config = signal<DayPilot.CalendarConfig>({
  // ...
  onBeforeGridLineRender: args => {
    if (args.type === "HorizontalBreak") {
      args.hidden = true;
    }
  },
  // ...
});

As an optional variation, use heights proportional to each period’s duration. In timeline(), replace height: 60 with height: (at(day, period.end).getTime() - at(day, period.start).getTime()) / 60000 * 1.2. At 1.2 pixels per minute, 45-, 60- and 75-minute periods have heights of 54, 72 and 90 pixels. The lesson boundaries stay the same.

Period Names and Time Ranges

Set timeHeaders to groupBy: "Cell" for one label per period. Use onBeforeTimeHeaderRender to override the default row header text. With a manual timeline, args.header.start identifies the period’s time of day, such as "08:15".

config = signal<DayPilot.CalendarConfig>({
  // ...
  timeHeaders: [{groupBy: "Cell", width: 132}],
  // ...
  onBeforeTimeHeaderRender: args => {
    const period = periods.find(p => p.start === args.header.start);
    if (!period) { return; }
    args.header.text = `${period.name} ${period.start} – ${period.end}`;
    args.header.html = `<div class="lesson-period">${period.name}<small>${period.start} – ${period.end}</small></div>`;
  },
  // ...
});

Supply both text and html: plain text carries the full label, while HTML places the time range on a separate line. The names and times in this example are trusted constants. Encode any values supplied by users before inserting them into HTML.

Loading Lessons with Real Timestamps

The Calendar uses start and end date/time fields. These values now express meaningful lesson times and can be stored directly in a database. The end is exclusive. Here is part of the simulated server response in src/app/calendar/data.service.ts:

return of([
  {id: "math", text: "Mathematics", start: `${monday}T08:15:00`, end: `${monday}T09:00:00`, tags: {color: "#f9cb9c"}},
  {id: "science", text: "Science lab", start: `${monday}T10:30:00`, end: `${monday}T12:40:00`, tags: {color: "#b6d7a8"}},
  // ...
]);

Science lab occupies periods 3 and 4. Its real interval is 10:30–12:40, including the omitted 11:15–11:25 break. Likewise, Art workshop spans lunch from 11:25 to 14:15. Hiding a break removes its pixels, not its elapsed time from an event’s start/end interval.

ngOnInit(): void {
    this.ds.getEvents(this.week()).subscribe(result => this.events.set(result));
  }

The sample loads one week of lessons in memory. Other weeks start empty. Navigation changes the dates and rebuilds the reference timeline without reloading the original events, so edits remain when you return. Changes last for the current page session; a production application would load and save them through its backend.

Creating and Resizing Lessons

Select an empty period or drag through several rows to create a lesson. The Calendar opens a prompt for the subject. Moving and resizing use "Update" handling. After either operation, changed() copies the control’s current event list into the Angular signal so later creations and navigation retain the changes.

onTimeRangeSelecting: args => {
      args.allowed = this.validRange(args.start, args.end);
    },
    onTimeRangeSelected: async args => {
      const modal = await DayPilot.Modal.prompt("New lesson:", "Lesson");
      args.control.clearSelection();
      if (modal.canceled || !modal.result) { return; }
      const lesson: DayPilot.EventData = {
        id: DayPilot.guid(), text: modal.result,
        start: args.start, end: args.end, tags: {color: "#a4c2f4"}
      };
      this.events.update(events => [...events, lesson]);
      this.status.set(`Created: ${modal.result} · ${args.start.toString("ddd H:mm")} – ${args.end.toString("H:mm")}`);
    },

The manual grid supplies period boundaries for selection and resizing. The validRange() guard also rejects ranges with an unrecognized boundary or an end on another day. This keeps a lesson within one school day.

validRange(start: DayPilot.Date, end: DayPilot.Date): boolean {
    return start.getDatePart().getTime() === end.getDatePart().getTime() &&
      periods.some(p => p.start === start.toString("HH:mm")) &&
      periods.some(p => p.end === end.toString("HH:mm")) && start.getTime() < end.getTime();
  }
config = signal<DayPilot.CalendarConfig>({
  // ...
  onEventResizing: args => {
    args.allowed = this.validRange(args.start, args.end);
  },
  onEventResized: args => this.changed("Resized", args.e)
});

Moving Lessons while Preserving Period Count

angular timetable moving

Preserving elapsed duration is insufficient when periods have different lengths. Mathematics lasts 45 minutes in period 1. If it moves to period 2, it must fill 09:10–10:10 (60 minutes). A double lesson must still occupy two periods, even if the destination includes a different break or lunch.

The following onEventMoving handler adapts the released Timetable demo. Find the original first and last period indexes, then offset the proposed destination index by the same number of rows. Reject moves beyond period 7; otherwise replace the proposed end with the destination period’s real end time.

onEventMoving: args => {
      const index = periods.findIndex(p => p.start === args.start.toString("HH:mm"));
      const first = periods.findIndex(p => p.start === args.e.start().toString("HH:mm"));
      const last = periods.findIndex(p => p.end === args.e.end().toString("HH:mm"));
      const target = index + last - first;
      if (index < 0 || first < 0 || last < first || target >= periods.length) {
        args.allowed = false;
        return;
      }
      // Preserve period count, not elapsed minutes, at the destination.
      Object.assign(args, {end: at(args.start.getDatePart(), periods[target].end)});
      args.bottom.html = args.end.toString("H:mm");
    },
    onEventMoved: args => this.changed("Moved", args.e),

Object.assign() sets the destination end on the moving arguments. It accommodates the Angular package’s readonly declaration of that field while using the demo’s runtime behavior. The Calendar uses this value for the drag preview and the completed move. Updating args.bottom.html also keeps the floating end-time label consistent with the recalculated end.

changed(action: string, event: DayPilot.Event): void {
    this.events.set([...this.calendar.control.events.list]);
    this.status.set(`${action}: ${event.text()} · ${event.start().toString("ddd H:mm")} – ${event.end().toString("H:mm")}`);
  }

Timetable Event Colors

angular timetable colors

We specify the color using the tags object of each data item. Apply it using the onBeforeEventRender handler, which lets us customize the event rendering. The darker border and dark text keep the light lesson colors readable.

config = signal<DayPilot.CalendarConfig>({
  // ...
  onBeforeEventRender: args => {
    if (args.data.tags?.color) {
      args.data.backColor = args.data.tags.color;
      args.data.borderColor = "darker";
      args.data.fontColor = "#333333";
    }
  },
  // ...
});

Optional: Mapping Date and Period Count to Event Boundaries

You may prefer to store a date, the first period and a period count. Convert that compact representation to real boundaries using the same period array. firstPeriod is zero-based: period 3 has index 2. Validate the indexes before accessing the array.

// Optional storage adapter: firstPeriod is zero-based, periodCount is positive.
export function periodRange(date: string, firstPeriod: number, periodCount: number) {
  const last = firstPeriod + periodCount - 1;
  if (!Number.isInteger(firstPeriod) || !Number.isInteger(periodCount) ||
      firstPeriod < 0 || periodCount < 1 || last >= periods.length) {
    throw new Error("Invalid lesson period range");
  }
  const day = new DayPilot.Date(date).getDatePart();
  return {
    start: at(day, periods[firstPeriod].start),
    end: at(day, periods[last].end)
  };
}

For example, periodRange("2026-11-16", 2, 2) returns 10:30–12:40 on that date. This is a boundary lookup, not hour arithmetic. To map back after a move or resize, find the start time in periods[].start and the end time in periods[].end; the count is last - first + 1. Reject missing boundaries and cross-day ranges as in validRange(). The optional format does not change the fact that breaks within a multi-period lesson belong to its real elapsed interval.

Source Code and Running the Sample

The application uses Angular 22. Install dependencies with npm install, start the development server with npm start, and open the URL printed by Angular. Use npm run build for a production build. The Calendar component is in src/app/calendar/calendar.component.ts, period definitions and the optional adapter are in periods.ts, and lesson data is in data.service.ts.

The complete component below combines the timeline, headers and interaction handlers:

import {Component, ViewChild, OnInit, signal, computed} from "@angular/core";
import {DayPilot, DayPilotModule, DayPilotCalendarComponent} from "daypilot-pro-angular";
import {DataService} from "./data.service";
import {at, periods} from "./periods";

@Component({
  selector: 'calendar-component',
  standalone: true,
  imports: [DayPilotModule],
  providers: [DataService],
  template: `
    <div class="toolbar">
      <button (click)="navigate(-1)">Previous week</button>
      <button (click)="today()">This week</button>
      <button (click)="navigate(1)">Next week</button>
      <strong class="week-label">{{weekLabel()}}</strong>
    </div>
    <daypilot-calendar [config]="config" [events]="events" #calendar></daypilot-calendar>
    <p class="instructions">Select empty periods to create a lesson. Drag to move; drag an edge to resize.</p>
    <p class="status" aria-live="polite">{{status()}}</p>
  `
})
export class CalendarComponent implements OnInit {
  @ViewChild("calendar") calendar!: DayPilotCalendarComponent;

  week = signal(DayPilot.Date.today().firstDayOfWeek(1));
  weekLabel = computed(() => `${this.week().toString("MMM d")} – ${this.week().addDays(4).toString("MMM d, yyyy")}`);
  events = signal<DayPilot.EventData[]>([]);
  status = signal("Lesson times include breaks; the grid displays only lesson periods.");

  timeline(day: DayPilot.Date): NonNullable<DayPilot.CalendarConfig["timeline"]> {
    return periods.map(period => ({
      start: at(day, period.start),
      end: at(day, period.end),
      height: 60
    }));
  }

  validRange(start: DayPilot.Date, end: DayPilot.Date): boolean {
    return start.getDatePart().getTime() === end.getDatePart().getTime() &&
      periods.some(p => p.start === start.toString("HH:mm")) &&
      periods.some(p => p.end === end.toString("HH:mm")) && start.getTime() < end.getTime();
  }

  config = signal<DayPilot.CalendarConfig>({
    startDate: this.week(),
    viewType: "WorkWeek",
    weekStarts: 1,
    scale: "Manual",
    timeline: this.timeline(this.week()),
    heightSpec: "Full",
    timeHeaders: [{groupBy: "Cell", width: 132}],
    headerDateFormat: "ddd M/d",
    headerHeight: 32,
    durationBarVisible: false,
    showCurrentTime: false,
    eventClickHandling: "Disabled",
    eventHoverHandling: "Disabled",
    eventMoveHandling: "Update",
    eventResizeHandling: "Update",
    timeRangeSelectedHandling: "Enabled",
    eventMovingStartEndEnabled: true,
    eventResizingStartEndEnabled: true,
    eventMovingStartEndFormat: "H:mm",
    eventResizingStartEndFormat: "H:mm",
    onBeforeGridLineRender: args => {
      if (args.type === "HorizontalBreak") {
        args.hidden = true;
      }
    },
    onBeforeTimeHeaderRender: args => {
      const period = periods.find(p => p.start === args.header.start);
      if (!period) { return; }
      args.header.text = `${period.name} ${period.start} – ${period.end}`;
      args.header.html = `<div class="lesson-period">${period.name}<small>${period.start} – ${period.end}</small></div>`;
    },
    onBeforeEventRender: args => {
      if (args.data.tags?.color) {
        args.data.backColor = args.data.tags.color;
        args.data.borderColor = "darker";
        args.data.fontColor = "#333333";
      }
    },
    onTimeRangeSelecting: args => {
      args.allowed = this.validRange(args.start, args.end);
    },
    onTimeRangeSelected: async args => {
      const modal = await DayPilot.Modal.prompt("New lesson:", "Lesson");
      args.control.clearSelection();
      if (modal.canceled || !modal.result) { return; }
      const lesson: DayPilot.EventData = {
        id: DayPilot.guid(), text: modal.result,
        start: args.start, end: args.end, tags: {color: "#a4c2f4"}
      };
      this.events.update(events => [...events, lesson]);
      this.status.set(`Created: ${modal.result} · ${args.start.toString("ddd H:mm")} – ${args.end.toString("H:mm")}`);
    },
    onEventMoving: args => {
      const index = periods.findIndex(p => p.start === args.start.toString("HH:mm"));
      const first = periods.findIndex(p => p.start === args.e.start().toString("HH:mm"));
      const last = periods.findIndex(p => p.end === args.e.end().toString("HH:mm"));
      const target = index + last - first;
      if (index < 0 || first < 0 || last < first || target >= periods.length) {
        args.allowed = false;
        return;
      }
      // Preserve period count, not elapsed minutes, at the destination.
      Object.assign(args, {end: at(args.start.getDatePart(), periods[target].end)});
      args.bottom.html = args.end.toString("H:mm");
    },
    onEventMoved: args => this.changed("Moved", args.e),
    onEventResizing: args => {
      args.allowed = this.validRange(args.start, args.end);
    },
    onEventResized: args => this.changed("Resized", args.e)
  });

  constructor(private ds: DataService) {}

  ngOnInit(): void {
    this.ds.getEvents(this.week()).subscribe(result => this.events.set(result));
  }

  changed(action: string, event: DayPilot.Event): void {
    this.events.set([...this.calendar.control.events.list]);
    this.status.set(`${action}: ${event.text()} · ${event.start().toString("ddd H:mm")} – ${event.end().toString("H:mm")}`);
  }

  navigate(weeks: number): void {
    this.showWeek(this.week().addDays(weeks * 7));
  }

  today(): void {
    this.showWeek(DayPilot.Date.today().firstDayOfWeek(1));
  }

  showWeek(week: DayPilot.Date): void {
    this.calendar.control.clearSelection();
    this.week.set(week);
    this.config.update(config => ({...config, startDate: week, timeline: this.timeline(week)}));
  }
}

History

November 17, 2026: Uses Angular 22 and the Calendar’s manual timeline with real lesson periods, hidden breaks, and moves that preserve period count.