Your search did not match any results.

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
<div id="calendar-demo"> <div class="widget-container"> @(Html.DevExtreme().Calendar() .ID("calendar-container") .Value(DateTime.Now) .Disabled(false) .ZoomLevel(CalendarZoomLevel.Month) .OnValueChanged("calendar_valueChanged") ) </div> <div class="options"> <div class="caption">Options</div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Specified min value") .OnValueChanged("minValue_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Specified max value") .OnValueChanged("maxValue_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Disable weekend") .OnValueChanged("disabledDates_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Monday as the first day of a week") .OnValueChanged("firstDayOfWeek_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Use the Custom Cell Template") .Value(false) .OnValueChanged("useCustomTemplate") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Disabled") .OnValueChanged("disabledState_changed") ) </div> <div class="option"> <span>Zoom level</span> @(Html.DevExtreme().SelectBox() .DataSource(new[] { "month", "year", "decade", "century" }) .Value("month") .OnValueChanged("zoomLevel_changed") ) </div> <div class="option"> <span>Selected date</span> @(Html.DevExtreme().DateBox() .ID("selected-date") .Value(DateTime.Now) .Width("100%") .OnValueChanged("selectedDate_changed") ) </div> </div> </div> <script> var date = new Date().getTime(); function getCalendarInstance() { return $("#calendar-container").dxCalendar("instance"); } function isWeekend(date) { var day = date.getDay(); return day === 0 || day === 6; } function getCellTemplate(data) { var cssClass = ""; if (data.view === 'month') { if (isWeekend(data.date)) cssClass = "weekend"; $.each([[1, 0], [4, 6], [25, 11]], function (_, item) { if(data.date.getDate() === item[0] && data.date.getMonth() === item[1]) { cssClass = "holyday"; return false; } }); } return "<span class='" + cssClass + "'>" + data.text + "</span>"; } function calendar_valueChanged(data) { $("#selected-date").dxDateBox("instance").option("value", data.value); } function minValue_changed(data) { var calendar = getCalendarInstance(); if(data.value) { calendar.option("min", new Date(date - 1000 * 60 * 60 * 24 * 3)); } else { calendar.option("min", null); } } function maxValue_changed(data) { var calendar = getCalendarInstance(); if(data.value) { calendar.option("max", new Date(date + 1000 * 60 * 60 * 24 * 3)); } else { calendar.option("max", null); } } function disabledDates_changed(data) { var calendar = getCalendarInstance(); if (data.value) { calendar.option("disabledDates", function (data) { return data.view === "month" && isWeekend(data.date); }); } else { calendar.option("disabledDates", null); } } function firstDayOfWeek_changed(data) { var calendar = getCalendarInstance(); if(data.value) { calendar.option("firstDayOfWeek", 1); } else { calendar.option("firstDayOfWeek", 0); } } function useCustomTemplate(data) { getCalendarInstance().option("cellTemplate", data.value ? getCellTemplate : "cell"); } function disabledState_changed(data) { getCalendarInstance().option("disabled", data.value); } function zoomLevel_changed(data) { getCalendarInstance().option("zoomLevel", data.value); } function selectedDate_changed(data) { getCalendarInstance().option("value", data.value); } </script>
using Microsoft.AspNetCore.Mvc; namespace DevExtreme.NETCore.Demos.Controllers { public class CalendarController : Controller { public ActionResult Overview() { return View(); } } }
.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; }