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 "Set minimum date" and "Set maximum date" checkboxes to apply the properties.

If you need to disable specific dates, use the disabledDates property. Toggle the "Disable weekends" 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.

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

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

Backend API
@{ var zoomLevels = new[] { "month", "year", "decade", "century" }; var weekNumberRules = new[] { "auto", "firstDay", "firstFourDays", "fullWeek" }; var weekDays = new[] { new { Id = 0, Text = "Sunday" }, new { Id = 1, Text = "Monday" }, new { Id = 2, Text = "Tuesday" }, new { Id = 3, Text = "Wednesday" }, new { Id = 4, Text = "Thursday" }, new { Id = 5, Text = "Friday" }, new { Id = 6, Text = "Saturday" }, }; } <div id="container"> <div class="calendar-container"> @(Html.DevExtreme().Calendar() .ID("calendar-container") .Value(DateTime.Now) .Disabled(false) .FirstDayOfWeek(FirstDayOfWeek.Sunday) .ZoomLevel(CalendarZoomLevel.Month) .OnValueChanged("calendar_valueChanged") .OnOptionChanged("calendar_optionChanged") ) </div> <div class="options"> <div class="caption">Options</div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Set minimum date") .OnValueChanged("minValue_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Set maximum date") .OnValueChanged("maxValue_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Disable weekends") .OnValueChanged("disabledDates_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Show week numbers") .OnValueChanged("showWeekNumbers_changed") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Use custom cell template") .Value(false) .OnValueChanged("useCustomTemplate") ) </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Disable the calendar") .OnValueChanged("disabledState_changed") ) </div> <div class="option"> <span>First day of week</span> @(Html.DevExtreme().SelectBox() .DataSource(weekDays) .InputAttr("aria-label", "First Day of Week") .Value(FirstDayOfWeek.Sunday) .ValueExpr("Id") .DisplayExpr("Text") .OnValueChanged("firstDayOfWeek_changed") ) </div> <div class="option"> <span>Week number rule</span> @(Html.DevExtreme().SelectBox() .DataSource(weekNumberRules) .Value(WeekNumberRule.Auto) .InputAttr("aria-label", "Week Number Rule") .OnValueChanged("weekNumberRule_changed") ) </div> <div class="option"> <span>Zoom level</span> @(Html.DevExtreme().SelectBox() .ID("zoom-level") .DataSource(zoomLevels) .InputAttr("aria-label", "Zoom Level") .Value(zoomLevels[0]) .OnValueChanged("zoomLevel_changed") ) </div> <div class="option"> <span>Selected date</span> @(Html.DevExtreme().DateBox() .InputAttr("aria-label", "Date") .ID("selected-date") .Value(DateTime.Now) .OnValueChanged("selectedDate_changed") ) </div> </div> </div> <script> var date = new Date().getTime(); var msInDay = 1000 * 60 * 60 * 24; function getCalendarInstance() { return $("#calendar-container").dxCalendar("instance"); } function getDateBoxInstance() { return $("#selected-date").dxDateBox("instance"); } function isWeekend(date) { var day = date.getDay(); return day === 0 || day === 6; } function getCellTemplate(data) { var cssClass = ""; if (data.view === 'month') { if (!data.date) { cssClass = "week-number"; } else { 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 = "holiday"; return false; } }); } } return "<span class='" + cssClass + "'>" + data.text + "</span>"; } function calendar_valueChanged(data) { getDateBoxInstance().option("value", data.value); } function calendar_optionChanged(data) { if (data.name === 'zoomLevel') { $("#zoom-level").dxSelectBox("instance").option('value', data.value); } } function minValue_changed(data) { const minDate = new Date(date - msInDay * 3); getCalendarInstance().option("min", data.value ? minDate : null); getDateBoxInstance().option("min", data.value ? minDate : null); } function maxValue_changed(data) { const maxDate = new Date(date + msInDay * 3); getCalendarInstance().option("max", data.value ? maxDate : null); getDateBoxInstance().option("max", data.value ? maxDate : 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) { getCalendarInstance().option("firstDayOfWeek", data.value); } function weekNumberRule_changed(data) { getCalendarInstance().option("weekNumberRule", data.value); } function showWeekNumbers_changed(data) { getCalendarInstance().option("showWeekNumbers", data.value); } 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(); } } }
#container { 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; }