React Scheduler - Customize Appointment
For a minor customization of Scheduler appointments, you can define specific fields in appointment data objects. For example, the following code generates three appointments: the first is not customized, the second is hidden, and the third is disabled.
jQuery
var appointments = [{ text: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:30:00.000Z"), endDate: new Date("2016-04-25T11:30:00.000Z") }, { text: "Book Flights to San Fran for Sales Trip", startDate: new Date("2016-04-25T12:00:00.000Z"), endDate: new Date("2016-04-25T13:00:00.000Z"), hidden: true }, { text: "Annual Meeting in Berlin", startDate: new Date("2016-04-26T11:00:00.000Z"), endDate: new Date("2016-04-26T13:00:00.000Z"), disabled: true } // ... ]; $(function () { $("#schedulerContainer").dxScheduler({ dataSource: appointments, currentDate: new Date(2016, 4, 25) }); });
Angular
import { DxSchedulerModule } from "devextreme-angular"; // ... export class AppComponent { appointments = [{ text: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:30:00.000Z"), endDate: new Date("2016-04-25T11:30:00.000Z") }, { text: "Book Flights to San Fran for Sales Trip", startDate: new Date("2016-04-25T12:00:00.000Z"), endDate: new Date("2016-04-25T13:00:00.000Z"), hidden: true }, { text: "Annual Meeting in Berlin", startDate: new Date("2016-04-26T11:00:00.000Z"), endDate: new Date("2016-04-26T13:00:00.000Z"), disabled: true } // ... ]; currentDate = new Date(2016, 4, 25); } @NgModule({ imports: [ // ... DxSchedulerModule ], // ... })
<dx-scheduler [dataSource]="appointments" [currentDate]="currentDate"> </dx-scheduler>
Vue
<template> <DxScheduler :data-source="appointments" :current-date="currentDate" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxScheduler from 'devextreme-vue/scheduler'; export default { components: { DxScheduler }, data() { return { currentDate: new Date(2016, 4, 25), appointments: [{ text: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:30:00.000Z"), endDate: new Date("2016-04-25T11:30:00.000Z") }, { text: "Book Flights to San Fran for Sales Trip", startDate: new Date("2016-04-25T12:00:00.000Z"), endDate: new Date("2016-04-25T13:00:00.000Z"), hidden: true }, { text: "Annual Meeting in Berlin", startDate: new Date("2016-04-26T11:00:00.000Z"), endDate: new Date("2016-04-26T13:00:00.000Z"), disabled: true } // ... ]; } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import Scheduler from 'devextreme-react/scheduler'; const appointments = [{ text: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:30:00.000Z"), endDate: new Date("2016-04-25T11:30:00.000Z") }, { text: "Book Flights to San Fran for Sales Trip", startDate: new Date("2016-04-25T12:00:00.000Z"), endDate: new Date("2016-04-25T13:00:00.000Z"), hidden: true }, { text: "Annual Meeting in Berlin", startDate: new Date("2016-04-26T11:00:00.000Z"), endDate: new Date("2016-04-26T13:00:00.000Z"), disabled: true } // ... ]; class App extends React.Component { render() { return ( <Scheduler dataSource={appointments} defaultCurrentDate={new Date(2016, 4, 25)} /> ); } } export default App;
If you need a more flexible solution, define a custom template. For Angular, AngularJS and Knockout apps, DevExtreme provides the dxTemplate markup component. The following code shows how to use dxTemplate to define templates for appointments.
Angular
<dx-scheduler [dataSource]="schedulerData" appointmentTemplate="appointmentTemplate" [currentDate]="currentDate"> <div *dxTemplate="let model of 'appointmentTemplate'"> <i>{{model.appointmentData.movie}}</i> <p>Price: ${{model.appointmentData.price}}</p> </div> </dx-scheduler>
import { DxSchedulerModule } from "devextreme-angular"; // ... export class AppComponent { schedulerData = [{ movie: "His Girl Friday", price: 5, startDate: new Date("2016-04-24T09:10:00.000Z"), endDate: new Date("2016-04-24T11:20:00.000Z") }, { movie: "Royal Wedding", price: 10, startDate: new Date("2016-04-24T10:05:00.000Z"), endDate: new Date("2016-04-24T11:30:00.000Z") }, // ... ]; currentDate = new Date(2016, 4, 24); } @NgModule({ imports: [ // ... DxSchedulerModule ], // ... })
AngularJS
<div ng-controller="DemoController"> <div dx-scheduler="{ dataSource: schedulerData, appointmentTemplate: 'appointment', currentDate: currentDate, }" dx-item-alias="model"> <div data-options="dxTemplate: { name: 'appointment' }"> <i>{{model.appointmentData.movie}}</i> <p>Price: ${{model.appointmentData.price}}</p> </div> </div> </div>
angular.module('DemoApp', ['dx']) .controller('DemoController', function DemoController($scope) { $scope.schedulerData = [{ movie: "His Girl Friday", price: 5, startDate: new Date("2016-04-24T09:10:00.000Z"), endDate: new Date("2016-04-24T11:20:00.000Z") }, { movie: "Royal Wedding", price: 10, startDate: new Date("2016-04-24T10:05:00.000Z"), endDate: new Date("2016-04-24T11:30:00.000Z") }, // ... ]; $scope.currentDate = new Date(2016, 4, 24); });
dx-item-alias
directive specifies the variable that is used to access the item object.Knockout
<div data-bind="dxScheduler: { dataSource: schedulerData, appointmentTemplate: 'appointment', currentDate: currentDate }"> <div data-options="dxTemplate: { name: 'appointment' }"> <i data-bind="text: appointmentData.movie"></i> <p>Price: $<span data-bind="text: appointmentData.price"></span></p> </div> </div>
var viewModel = { schedulerData: [{ movie: "His Girl Friday", price: 5, startDate: new Date("2016-04-24T09:10:00.000Z"), endDate: new Date("2016-04-24T11:20:00.000Z") }, { movie: "Royal Wedding", price: 10, startDate: new Date("2016-04-24T10:05:00.000Z"), endDate: new Date("2016-04-24T11:30:00.000Z") }, // ... ], currentDate: new Date(2016, 4, 24) }; ko.applyBindings(viewModel);
Vue
<template> <DxScheduler :data-source="appointments" :current-date="currentDate" appointment-template="appointment" > <template #appointment="{ data }"> <i>{{data.appointmentData.movie}}</i> <p>Price: ${{data.appointmentData.price}}</p> </template> </DxScheduler> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxScheduler from 'devextreme-vue/scheduler'; export default { components: { DxScheduler }, data() { return { currentDate: new Date(2016, 4, 25), appointments: [{ movie: "His Girl Friday", price: 5, startDate: new Date("2016-04-24T09:10:00.000Z"), endDate: new Date("2016-04-24T11:20:00.000Z") }, { movie: "Royal Wedding", price: 10, startDate: new Date("2016-04-24T10:05:00.000Z"), endDate: new Date("2016-04-24T11:30:00.000Z") }, // ... ]; } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import Scheduler from 'devextreme-react/scheduler'; const appointments = [{ movie: "His Girl Friday", price: 5, startDate: new Date("2016-04-24T09:10:00.000Z"), endDate: new Date("2016-04-24T11:20:00.000Z") }, { movie: "Royal Wedding", price: 10, startDate: new Date("2016-04-24T10:05:00.000Z"), endDate: new Date("2016-04-24T11:30:00.000Z") }, // ... ]; const renderAppointment = (model) => { return ( <React.Fragment> <i>{{model.appointmentData.movie}}</i> <p>Price: ${{model.appointmentData.price}}</p> </React.Fragment> ); } class App extends React.Component { render() { return ( <Scheduler dataSource={appointments} defaultCurrentDate={new Date(2016, 4, 25)} appointmentRender={renderAppointment} /> ); } } export default App;
If you use only jQuery, combine HTML markup for appointments manually with jQuery DOM manipulation methods. To apply this markup, use the appointmentTemplate callback function as shown in the following code.
var schedulerData = [{ movie: "His Girl Friday", price: 5, startDate: new Date("2016-04-24T09:10:00.000Z"), endDate: new Date("2016-04-24T11:20:00.000Z") }, { movie: "Royal Wedding", price: 10, startDate: new Date("2016-04-24T10:05:00.000Z"), endDate: new Date("2016-04-24T11:30:00.000Z") }, // ... ]; $(function () { $("#schedulerContainer").dxScheduler({ dataSource: schedulerData, appointmentTemplate: function (model, index, element) { element.append("<i>" + model.appointmentData.movie + "</i>"); element.append("<p>Price: $" + model.appointmentData.price + "</p>"); } }); });
You can also customize an individual appointment. For this purpose, declare a template for this appointment as a script and pass its id
to the template field of the appointment's data object.
<script id="individualTemplate" type="text/html"> <!-- ... --> </script>
var schedulerData = [{ movie: "Royal Wedding", startDate: new Date("2016-04-24T10:05:00.000Z"), endDate: new Date("2016-04-24T11:30:00.000Z"), template: $("#individualTemplate") }, { // ... }];
In addition, you can use a 3rd-party template engine to customize the UI component appearance. For more information, see the 3rd-Party Template Engines article.
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.