DevExtreme v24.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

JavaScript/jQuery Calendar - Overview

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

DevExtreme Accessibility Compliance
DevExtreme component libraries meet a variety of WCAG and Section 508 compliance standards. To assess this demo’s accessibility level, click the Run AXE® Validation button to launch the AXE® web accessibility evaluation tool.
All trademarks or registered trademarks are property of their respective owners. AXE® Terms of Use
The overall accessibility level of your application depends on the Calendar features used.
Backend API
$(() => { const zoomLevels = ['month', 'year', 'decade', 'century']; const weekDays = [ { id: 0, text: 'Sunday' }, { id: 1, text: 'Monday' }, { id: 2, text: 'Tuesday' }, { id: 3, text: 'Wednesday' }, { id: 4, text: 'Thursday' }, { id: 5, text: 'Friday' }, { id: 6, text: 'Saturday' }, ]; const weekNumberRules = ['auto', 'firstDay', 'firstFourDays', 'fullWeek']; const calendar = $('#calendar').dxCalendar({ value: new Date(), disabled: false, firstDayOfWeek: 0, showWeekNumbers: false, weekNumberRule: 'auto', zoomLevel: zoomLevels[0], onValueChanged(data) { selectedDate.option('value', data.value); }, onOptionChanged(data) { if (data.name === 'zoomLevel') { zoomLevel.option('value', data.value); } }, }).dxCalendar('instance'); const zoomLevel = $('#zoom-level').dxSelectBox({ dataSource: zoomLevels, value: zoomLevels[0], inputAttr: { 'aria-label': 'Zoom Level' }, onValueChanged(data) { calendar.option('zoomLevel', data.value); }, }).dxSelectBox('instance'); const selectedDate = $('#selected-date').dxDateBox({ value: new Date(), inputAttr: { 'aria-label': 'Date' }, onValueChanged(data) { calendar.option('value', data.value); }, }).dxDateBox('instance'); $('#custom-cell').dxCheckBox({ text: 'Use custom cell template', value: false, onValueChanged(data) { calendar.option('cellTemplate', data.value ? getCellTemplate : 'cell'); }, }); $('#disabled').dxCheckBox({ text: 'Disable the calendar', onValueChanged(data) { calendar.option('disabled', data.value); }, }); $('#week-numbers').dxCheckBox({ text: 'Show week numbers', onValueChanged(data) { calendar.option('showWeekNumbers', data.value); }, }); $('#first-day-of-week').dxSelectBox({ dataSource: weekDays, value: 0, valueExpr: 'id', inputAttr: { 'aria-label': 'First Day of Week' }, displayExpr: 'text', onValueChanged(data) { calendar.option('firstDayOfWeek', data.value); }, }); $('#week-number-rule').dxSelectBox({ dataSource: weekNumberRules, value: weekNumberRules[0], inputAttr: { 'aria-label': 'Week Number Rule' }, onValueChanged(data) { calendar.option('weekNumberRule', data.value); }, }); const holidays = [[1, 0], [4, 6], [25, 11]]; function isWeekend(d) { const day = d.getDay(); return day === 0 || day === 6; } function getCellTemplate(data) { let cssClass = ''; if (data.view === 'month') { if (!data.date) { cssClass = 'week-number'; } else { if (isWeekend(data.date)) { cssClass = 'weekend'; } $.each(holidays, (_, item) => { if (data.date.getDate() === item[0] && data.date.getMonth() === item[1]) { cssClass = 'holiday'; return false; } return true; }); } } return `<span class='${cssClass}'>${data.text}</span>`; } });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <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=5.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/24.1.7/css/dx.light.css" /> <script src="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" id="calendar-demo"> <div class="calendar-container"> <div id="calendar"></div> </div> <div class="options"> <div class="caption">Options</div> <div class="option"> <span>Zoom level</span> <div id="zoom-level"></div> </div> <div class="option"> <span>Selected date</span> <div id="selected-date"></div> </div> <div class="option"> <div id="custom-cell"></div> </div> <div class="option"> <div id="disabled"></div> </div> <div class="caption option"> <span>Week numeration</span> </div> <div class="option"> <div id="week-numbers"></div> </div> <div class="option"> <span>First day of week</span> <div id="first-day-of-week"></div> </div> <div class="option"> <span>Week number rule</span> <div id="week-number-rule"></div> </div> </div> </div> </body> </html>
#calendar-demo { display: flex; } .calendar-container { display: flex; flex-direction: column; flex-grow: 1; align-items: center; justify-content: center; } .dx-calendar-cell:not(.dx-calendar-other-month) .weekend, .dx-calendar-cell:not(.dx-calendar-other-month) .holiday { 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) .holiday { color: #ff3030; } .dx-state-disabled.dx-calendar .dx-calendar-cell:not(.dx-calendar-other-month) .holiday { color: #ff8080; } .dx-calendar-week-number-cell .week-number { font-style: italic; } .caption { font-weight: 500; font-size: 18px; } .options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); } .option { margin-top: 10px; }

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

  • Date
    Specifies the date directly.

  • Number
    Specifies the date with a timestamp (total milliseconds since 1970/01/01).

  • String
    Specifies the date with a string value. The UI component supports the following formats of a date string:

    • "yyyy-MM-dd" (for example, "2017-03-06")
    • "yyyy-MM-ddTHH:mm:ss" (for example, "2017-03-27T16:54:48")
    • "yyyy-MM-ddTHH:mm:ssZ" (for example, "2017-03-27T13:55:41Z")
    • "yyyy-MM-ddTHH:mm:ssx" (for example, "2017-03-27T16:54:10+03")
  • Array of the formats mentioned before
    Available only for 'multiple' and 'range' selection modes. The array includes all selected dates.

Specify First Day of Week and Display Week Numbers

To specify the first day of the week, assign its index (0 - for Sunday, 1 - for Monday, and so on) to the firstDayOfWeek property. You can also display a column with week numbers. For this, enable the showWeekNumbers property.

The start of the first week of the year depends on the locale. If you want to apply a specific rule, use the weekNumberRule property.

Handle Value Change

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

Customize Cell Appearance

Use the cellTemplate property to customize cell appearance. In this demo, the following customizations are applied when you toggle the "Use custom cell template" checkbox:

  • All the weekends on the JavaScript Calendar become blue.

  • All the holidays become red.

  • If a column with week numbers is shown, week numbers are italicized.

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 JavaScript Calendar.

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