Your search did not match any results.
Calendar

Calendar

When you add a Calendar to an application, you need to specify its value in one of the following formats:

  • Date objects

  • The number of milliseconds since 00:00:00 on January 1, 1970

  • Strings that match the following patterns:

    • 'yyyy-MM-dd'
    • 'yyyy-MM-ddTHH:mm:ss'
    • 'yyyy-MM-ddTHH:mm:ssZ'
    • 'yyyy-MM-ddTHH:mm:ssx'

This demo shows how to use additional properties to customize your Calendar. You can toggle the checkboxes on the right to change the Calendar in real time.

Disable Dates

Use the min and max properties to specify the range of available dates. In this demo, these properties limit the range to three days before and after the current date. Enable the "Specified min value" and "Specified max value" checkboxes to apply the properties.

If you need to disable specific dates, use the disabledDates property. Toggle the "Disable weekend" checkbox to see how this setting affects the component's behavior. You can specify either an array of predefined dates or a function that determines whether a date is available.

Set the Beginning of the Week

To specify the first day of the week, pass its index (0 - for Sunday, 1 - for Monday, and so on) to the firstDayOfWeek property.

Handle Value Change

Set the onValueChanged property to handle the value change. In this demo, the DateBox and the Calendar both use this property to pass values between each other. You can use one of these components to change the date. See how it affects the other.

Customize Cell Appearance

Use the cellTemplate property to customize cell appearance. In this demo, when you toggle the "Use the Custom Cell Template" checkbox, all the weekends on the Calendar become blue, and all the holidays become red. You can set your own function that changes the class of the span element that contains cell text.

Other Customizations

Set the disabled property to disable the Calendar.

To specify the initial calendar view (month, year, decade, or century), set the zoomLevel property.

Backend API
Copy to CodePen
Apply
Reset
const DemoApp = angular.module('DemoApp', ['dx']); DemoApp.controller('DemoController', ($scope) => { const now = new Date(); $scope.zoomLevels = ['month', 'year', 'decade', 'century']; $scope.currentValue = new Date(); $scope.calendarDisabled = false; $scope.isMondayFirst = 0; $scope.minDateValue = null; $scope.maxDateValue = null; $scope.zoomLevel = $scope.zoomLevels[0]; $scope.cellTemplate = 'cell'; $scope.setMinDate = function (e) { if (e.value) { $scope.minDateValue = new Date(now.getTime() - 1000 * 60 * 60 * 24 * 3); } else { $scope.minDateValue = null; } }; $scope.setMaxDate = function (e) { if (e.value) { $scope.maxDateValue = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 3); } else { $scope.maxDateValue = null; } }; $scope.disableWeekend = function (e) { if (e.value) { $scope.disabledDates = function (data) { return data.view === 'month' && isWeekend(data.date); }; } else { $scope.disabledDates = null; } }; $scope.setFirstDay = function (e) { if (e.value) { $scope.firstDay = 1; } else { $scope.firstDay = 0; } }; $scope.useCellTemplate = function (e) { if (e.value) { $scope.cellTemplate = getCellTemplate; } else { $scope.cellTemplate = 'cell'; } }; const holydays = [[1, 0], [4, 6], [25, 11]]; function isWeekend(date) { const day = date.getDay(); return day === 0 || day === 6; } function getCellTemplate(data) { let cssClass = ''; if (data.view === 'month') { if (isWeekend(data.date)) { cssClass = 'weekend'; } $.each(holydays, (_, item) => { if (data.date.getDate() === item[0] && data.date.getMonth() === item[1]) { cssClass = 'holyday'; return false; } return true; }); } return `<span class='${cssClass}'>${data.text}</span>`; } });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.2.7/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.2.7/css/dx.light.css" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script> <script>window.angular || document.write(decodeURIComponent('%3Cscript src="js/angular.min.js"%3E%3C/script%3E'))</script> <script src="https://cdn3.devexpress.com/jslib/21.2.7/js/dx.all.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container" ng-app="DemoApp" ng-controller="DemoController"> <div id="calendar-demo"> <div class="widget-container"> <div id="calendar-container" dx-calendar="{ bindingOptions: { min: 'minDateValue', max: 'maxDateValue', disabledDates: 'disabledDates', firstDayOfWeek: 'firstDay', disabled: 'calendarDisabled', value: 'currentValue', zoomLevel: 'zoomLevel', cellTemplate: 'cellTemplate' } }" ></div> </div> <div class="options"> <div class="caption">Options</div> <div class="option"> <div dx-check-box="{ text: 'Specified min value', value: false, onValueChanged: setMinDate }" ></div> </div> <div class="option"> <div dx-check-box="{ text: 'Specified max value', value: false, onValueChanged: setMaxDate }" ></div> </div> <div class="option"> <div dx-check-box="{ text: 'Disable weekend', value: false, onValueChanged: disableWeekend }" ></div> </div> <div class="option"> <div dx-check-box="{ text: 'Monday as the first day of a week', value: false, onValueChanged: setFirstDay }" ></div> </div> <div class="option"> <div dx-check-box="{ text: 'Use the Custom Cell Template', value: false, onValueChanged: useCellTemplate }" ></div> </div> <div class="option"> <div dx-check-box="{ text: 'Disabled', bindingOptions: { value: 'calendarDisabled' } }" ></div> </div> <div class="option"> <span>Zoom level</span> <div id="zoom-level" dx-select-box="{ dataSource: zoomLevels, bindingOptions: { value: 'zoomLevel' } }" ></div> </div> <div class="option"> <span>Selected date</span> <div id="selected-date" dx-date-box="{ width: '100%', bindingOptions: { value: 'currentValue' } }" ></div> </div> </div> </div> </div> </body> </html>
.widget-container { margin-right: 320px; } #calendar-container { margin: auto; } .dx-calendar-cell:not(.dx-calendar-other-month) .weekend, .dx-calendar-cell:not(.dx-calendar-other-month) .holyday { text-shadow: none; font-weight: bold; } .dx-calendar-cell:not(.dx-calendar-other-month) .weekend { color: #3030ff; } .dx-state-disabled.dx-calendar .dx-calendar-cell:not(.dx-calendar-other-month) .weekend { color: #8080ff; } .dx-calendar-cell:not(.dx-calendar-other-month) .holyday { color: #ff3030; } .dx-state-disabled.dx-calendar .dx-calendar-cell:not(.dx-calendar-other-month) .holyday { color: #ff8080; } .options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); position: absolute; right: 0; top: 0; bottom: 0; width: 260px; } .caption { font-weight: 500; font-size: 18px; } .option { margin-top: 10px; }