Angular Scheduler - Getting Started
The Scheduler component emulates the user interface of Calendar applications on Windows or Mac OS.
This tutorial adds DevExtreme Scheduler to a page, binds the component to data, and configures core Scheduler features.
Each section covers a single configuration step. The complete code is available in the following GitHub repository:
Create a Scheduler
Add DevExtreme to your Angular application and use the following code to create a Scheduler:
- <dx-scheduler id="scheduler">
- <!-- Configuration goes here -->
- </dx-scheduler>
- import { Component } from '@angular/core';
- import { DxSchedulerModule } from 'devextreme-angular/ui/scheduler';
- @Component({
- imports: [DxSchedulerModule],
- // ...
- })
- export class AppComponent {
- }
- #scheduler {
- height: 600px;
- }
Bind the Scheduler to Data
The DevExtreme Scheduler supports the following data source types:
To bind Scheduler to data, configure the dataSource property. Specify data field names following the structure of the SchedulerAppointment interface. To use custom field names, specify the following properties:
- <dx-scheduler
- [dataSource]="appointments"
- textExpr="title"
- allDayExpr="dayLong"
- recurrenceRuleExpr="recurrence">
- </dx-scheduler>
- import { Component } from '@angular/core';
- import { Appointment, AppService } from './app.service';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css'],
- providers: [AppService]
- })
- export class AppComponent {
- appointments: Appointment[];
- constructor(service: AppService) {
- this.appointments = service.getAppointments();
- }
- }
- import { Injectable } from '@angular/core';
- export class Appointment {
- title: string;
- startDate: Date;
- endDate: Date;
- dayLong?: boolean;
- recurrence?: string;
- }
- const appointments: Appointment[] = [
- {
- title: "Install New Database",
- startDate: new Date("2021-05-23T08:45:00.000Z"),
- endDate: new Date("2021-05-23T09:45:00.000Z")
- }, {
- title: "Create New Online Marketing Strategy",
- startDate: new Date("2021-05-24T09:00:00.000Z"),
- endDate: new Date("2021-05-24T11:00:00.000Z")
- }, {
- title: "Upgrade Personal Computers",
- startDate: new Date("2021-05-25T10:15:00.000Z"),
- endDate: new Date("2021-05-25T13:30:00.000Z")
- }, {
- title: "Customer Workshop",
- startDate: new Date("2021-05-26T08:00:00.000Z"),
- endDate: new Date("2021-05-26T10:00:00.000Z"),
- dayLong: true,
- recurrence: "FREQ=WEEKLY;BYDAY=TU,FR;COUNT=10"
- }, {
- title: "Prepare Development Plan",
- startDate: new Date("2021-05-27T08:00:00.000Z"),
- endDate: new Date("2021-05-27T10:30:00.000Z")
- }, {
- title: "Testing",
- startDate: new Date("2021-05-23T09:00:00.000Z"),
- endDate: new Date("2021-05-23T10:00:00.000Z"),
- recurrence: "FREQ=WEEKLY;INTERVAL=2;COUNT=2"
- }, {
- title: "Meeting of Instructors",
- startDate: new Date("2021-05-24T10:00:00.000Z"),
- endDate: new Date("2021-05-24T11:15:00.000Z"),
- recurrence: "FREQ=DAILY;BYDAY=WE;UNTIL=20211001"
- }, {
- title: "Recruiting students",
- startDate: new Date("2021-05-25T08:00:00.000Z"),
- endDate: new Date("2021-05-25T09:00:00.000Z"),
- recurrence: "FREQ=YEARLY",
- }, {
- title: "Monthly Planning",
- startDate: new Date("2021-05-26T09:30:00.000Z"),
- endDate: new Date("2021-05-26T10:45:00.000Z"),
- recurrence: "FREQ=MONTHLY;BYMONTHDAY=28;COUNT=1"
- }, {
- title: "Open Day",
- startDate: new Date("2021-05-27T09:30:00.000Z"),
- endDate: new Date("2021-05-27T19:00:00.000Z"),
- }
- ];
- @Injectable({
- providedIn: 'root'
- })
- export class AppService {
- getAppointments(): Appointment[] {
- return appointments;
- }
- }
Set the Current Date
Use currentDate to specify the date displayed in the Scheduler:
- <dx-scheduler
- [(currentDate)]="currentDate">
- </dx-scheduler>
- import { Component } from '@angular/core';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.css']
- })
- export class AppComponent {
- currentDate: Date = new Date(2021, 4, 25);
- }
Configure Views
Read Tutorial: View Types Read Tutorial: Customize Individual Views
DevExtreme Scheduler ships with the following view types:
Specify the views[] array to define and customize Scheduler views. Specify each view's type value.
This example specifies the following views: Day, Week, and Month. Day and Week views use custom startDayHour and endDayHour values. The Month view uses the default configuration.
You can also specify the initial Scheduler view using currentView. This example initializes the component in the Week view:
- <dx-scheduler
- currentView="week">
- <dxi-scheduler-view
- type="day"
- [startDayHour]="10"
- [endDayHour]="22">
- </dxi-scheduler-view>
- <dxi-scheduler-view
- type="week"
- [startDayHour]="10"
- [endDayHour]="22">
- </dxi-scheduler-view>
- <dxi-scheduler-view type="month"></dxi-scheduler-view>
- </dx-scheduler>
Edit Appointments
Read Tutorial: Add Appointments Read Tutorial: Update Appointments Read Tutorial: Delete Appointments
Scheduler allows users to add, update, and delete appointments. All editing operations are enabled in the default configuration. To disable specific operations, configure the editing properties.
This tutorial disables allowDragging:
- <dx-scheduler>
- <dxo-scheduler-editing
- [allowDragging]="false">
- </dxo-scheduler-editing>
- </dx-scheduler>
When users add, update, or delete appointments, Scheduler calls the following event handlers:
You can use these handlers to extend Scheduler's functionality. The following example configures onAppointmentAdding and onAppointmentUpdating to prevent recurring appointments from sharing cells with other appointments:
Time Zone Support
Read Tutorial: Time Zone Support
Scheduler displays all appointments in the client time zone in the default configuration. To use a different time zone, specify the timeZone property. This option accepts IANA time zone identifiers. This tutorial sets the time zone to "Europe/Berlin".
Users can also edit the time zones of individual appointments when editing.allowTimeZoneEditing is enabled:
- <dx-scheduler
- timeZone="Europe/Berlin"
- >
- <dxo-scheduler-editing
- [allowTimeZoneEditing]="true"
- ></dxo-scheduler-editing>
- <!-- ... -->
- </dx-scheduler>
Enable Adaptive Mode
The Scheduler interface can adapt to small screens. Set adaptivityEnabled to true to enable this capability. For more information, see the following demo:
- <dx-scheduler
- [adaptivityEnabled]="true"
- ></dx-scheduler>
For further information on the Scheduler component, refer to the following resources: