@@ -27,38 +27,114 @@ In `Range` selection mode you can get the start and end dates of a selected rang
2727
2828## Receive User Selection
2929
30- To receive the user selection, handle the ` ValueChanged ` . There are two ways of obtaining the user selection, depending on the chosen selection mode:
30+ ### Single Selection Mode
3131
32- * for ` Single ` selection mode - the event handler received a ` DateTime ` object that is the new selected date
33- * for ` Multiple ` selection mode - access the ` SelectedDates ` property of the component reference in the ` ValueChanged ` handler.
32+ Use the ` ValueChanged ` event. The handler receives a ` DateTime ` object as parameter which represents the new selected date.
3433
35- ## Disabled Dates
34+ > caption Handle Single selection in the Calendar
3635
37- To prevent the user from selecting certain dates (for example, holidays), add those dates to the ` DisabledDates ` collection.
36+ ```` CSHTML
37+ @* This example shows how to handle Single selection *@
3838
39- ## Examples
39+ <TelerikCalendar Date="@startDate"
40+ View="CalendarView.Month"
41+ SelectionMode="@CalendarSelectionMode.Single"
42+ ValueChanged="SelectionHandler">
43+ </TelerikCalendar>
4044
41- > caption Handle calendar date selection and disable certain dates from being selected
45+ <p>
46+ Selected Date: @SelectedDate
47+ </p>
4248
43- ```` CSHTML
44- The user will not be able to select the first and second of April 2019.
49+ @code {
50+ private DateTime SelectedDate { get; set; }
51+ private DateTime startDate = new DateTime(2019, 5, 2);
52+ private TelerikCalendar CalendarRef { get; set; }
53+
54+ public void SelectionHandler(DateTime selectedDate)
55+ {
56+ SelectedDate = selectedDate;
57+ }
58+ }
59+ ````
60+
61+ ### Multiple Selection Mode
4562
46- <h4>Single Selection</h4>
63+ Use the ` SelectedDates ` property of the component reference in the ` ValueChanged ` handler.
4764
48- <TelerikCalendar SelectionMode="@CalendarSelectionMode.Single" ValueChanged="@SingleSelectionChangeHandler"
49- DisabledDates="@DisabledDates" @bind-Date="@startDate">
65+ > caption Handle Multiple selection in the Calendar
66+
67+ ```` CSHTML
68+ @* This example shows how to handle Multiple selection *@
69+
70+ <TelerikCalendar Date="@startDate"
71+ View="@CalendarView.Month"
72+ SelectionMode="@CalendarSelectionMode.Multiple"
73+ ValueChanged="@SelectionHandler"
74+ @ref="@CalendarRef">
5075</TelerikCalendar>
51- <br />
52- @if (selectedDate != null )
76+
77+ @if (SelectedDates.Any() )
5378{
54- @selectedDate.Value.ToString("dd MMM yyyy");
79+ <ul>
80+ @foreach (var date in SelectedDates)
81+ {
82+ <li>
83+ @date
84+ </li>
85+ }
86+ </ul>
5587}
5688
89+ @code {
90+ public List<DateTime> SelectedDates { get; set; } = new List<DateTime>();
91+ private DateTime startDate = new DateTime(2019, 5, 2);
92+ private TelerikCalendar CalendarRef { get; set; }
5793
58- <h4>Multiple Selection</h4>
94+ public void SelectionHandler()
95+ {
96+ SelectedDates = CalendarRef.SelectedDates;
97+ }
98+ }
99+ ````
100+ ### Range Selection Mode
101+
102+ Use the ` RangeStart ` , representing the first date of the selection, and the ` RangeEnd ` - the last date of the selection.
103+
104+ > caption Handle Range selection
105+
106+ ```` CSHTML
107+ @* This example shows how to handle Range selection *@
59108
60- <TelerikCalendar SelectionMode="@CalendarSelectionMode.Multiple" ValueChanged="@MultipleSelectionChangeHandler"
61- DisabledDates="@DisabledDates" @bind-Date="@startDate" @ref="multipleSelCalendar">
109+ <TelerikCalendar Views="2"
110+ Date="@Date"
111+ RangeStart="@RangeStart"
112+ RangeEnd="@RangeEnd"
113+ SelectionMode="@CalendarSelectionMode.Range">
114+ </TelerikCalendar>
115+
116+ @code {
117+ public static DateTime dateTimeNow { get; set; } = DateTime.Now;
118+ public DateTime Date { get; set; } = dateTimeNow.AddDays(-5);
119+ public DateTime RangeStart { get; set; } = dateTimeNow;
120+ public DateTime RangeEnd { get; set; } = dateTimeNow.AddDays(15);
121+ }
122+ ````
123+
124+ ### Disabled Dates
125+
126+ To prevent the user from selecting certain dates (for example, holidays), add those dates to the ` DisabledDates ` collection.
127+
128+ > caption Handle Disabled dates with Calendar Multiple selection
129+
130+ ```` CSHTML
131+ The user will not be able to select the first and second of April 2019.
132+
133+ <TelerikCalendar SelectionMode="@CalendarSelectionMode.Multiple"
134+ ValueChanged="@MultipleSelectionChangeHandler"
135+ DisabledDates="@DisabledDates"
136+ @bind-Date="@startDate"
137+ @ref="multipleSelCalendar">
62138</TelerikCalendar>
63139<br />
64140@if (chosenDates != null && chosenDates.Count > 0)
@@ -78,15 +154,8 @@ The user will not be able to select the first and second of April 2019.
78154 private List<DateTime> DisabledDates = new List<DateTime>() { new DateTime(2019, 4, 1), new DateTime(2019, 4, 2) };
79155
80156 // fields to store and render the user selection
81- private DateTime? selectedDate { get; set; } = null;
82157 private List<DateTime> chosenDates { get; set; }
83158
84- private void SingleSelectionChangeHandler(DateTime newValue)
85- {
86- // with single selection, the argument is a single DateTime object with the new selection
87- selectedDate = newValue;
88- }
89-
90159 // reference used to obtain the selected dates from a multiple selection calendar
91160 private Telerik.Blazor.Components.TelerikCalendar multipleSelCalendar;
92161 private void MultipleSelectionChangeHandler()
@@ -98,7 +167,6 @@ The user will not be able to select the first and second of April 2019.
98167
99168````
100169
101-
102170## See Also
103171
104172 * [ Live Demo: Calendar Selection] ( https://demos.telerik.com/blazor-ui/calendar/selection )
0 commit comments