Your search did not match any results.

Calendar - Overview

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.

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="calendar-demo"> <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"> <span>Zoom level</span> @(Html.DevExtreme().SelectBox() .ID("zoom-level") .InputAttr("aria-label", "Zoom Level") .DataSource(zoomLevels) .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 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="caption option"> <span>Week numeration</span> </div> <div class="option"> @(Html.DevExtreme().CheckBox() .Text("Show week numbers") .OnValueChanged("showWeekNumbers_changed") ) </div> <div class="option"> <span>First day of week</span> @(Html.DevExtreme().SelectBox() .DataSource(weekDays) .Value(FirstDayOfWeek.Sunday) .InputAttr("aria-label", "First Day of Week") .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> </div> <script> var date = new Date().getTime(); 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 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(); } } }
#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 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 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.