Your search did not match any results.

Calendar - Multiple Selection

This demo applies different selection modes and date availability options to the Calendar component.

Backend API
@{ var selectionModes = new[] { "single", "multiple", "range" }; } <div id="calendar-demo"> <div class="calendar-container"> @(Html.DevExtreme().Calendar() .ID("calendar-container") .Value(new JS("initialValues")) .ShowWeekNumbers(true) .SelectWeekOnClick(true) .SelectionMode(CalendarSelectionMode.Range) ) </div> <div class="options"> <div class="caption">Options</div> <div class="option"> @(Html.DevExtreme().CheckBox() .Value(true) .Text("Select week on click") .OnValueChanged("selectWeekOnClick_changed") ) </div> <div class="option"> <span>Selection mode</span> @(Html.DevExtreme().SelectBox() .DataSource(selectionModes) .Value(CalendarSelectionMode.Range) .InputAttr("aria-label", "Selection Mode") .OnValueChanged("selectionMode_changed") ) </div> <div class="caption option"> <span>Date availability</span> </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().Button() .Text("Clear value") .OnClick("clearButton_clicked") ) </div> </div> </div> <script> var date = new Date().getTime(); var msInDay = 1000 * 60 * 60 * 24; var initialValues = [date, date + msInDay]; function getCalendarInstance() { return $("#calendar-container").dxCalendar("instance"); } function isWeekend(date) { var day = date.getDay(); return day === 0 || day === 6; } function minValue_changed(data) { const minDate = new Date(date - msInDay * 3); getCalendarInstance().option("min", data.value ? minDate : null); } function maxValue_changed(data) { const maxDate = new Date(date + msInDay * 3); getCalendarInstance().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 selectWeekOnClick_changed(data) { getCalendarInstance().option("selectWeekOnClick", data.value); } function selectionMode_changed(data) { getCalendarInstance().option("selectionMode", data.value); } function clearButton_clicked(data) { getCalendarInstance().clear(); } </script>
using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class CalendarController : Controller { public ActionResult MultipleSelection() { return View(); } } }
#calendar-demo { display: flex; } .calendar-container { display: flex; flex-direction: column; flex-grow: 1; align-items: center; justify-content: center; } .caption { font-weight: 500; font-size: 18px; } .options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); } .option { margin-top: 10px; }

Selection Modes

The selected value or values are stored in the value property. The following selection modes are available:

  • 'single'
    A user can select only a single date at any given time.

  • 'multiple'
    A user can select multiple dates simultaneously.

  • 'range'
    A user can select a range of dates. The first and the last date in the range are stored in the value property.

If you enable selectWeekOnClick in 'multiple' or 'range' modes, users can select a week by clicking on the week number.

Disable and Clear 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 component behavior. You can specify either an array of predefined dates or a function that determines whether a date is available.

When using 'multiple' and 'range' selection modes, the behavior of disabled dates in the Calendar is as follows:

  • If you specify the value property programmatically, disabled dates are selected in the values array.

  • If you use the UI to change selection (click on dates or weeks, the Enter key), you cannot select disabled dates in 'multiple' mode. In 'range' mode, disabled dates cannot start or end a range, but can be included in the middle.

To clear selected values, call the Calendar clear() method.