You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: components/calendar/events.md
+33-27Lines changed: 33 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,8 +15,7 @@ This article explains the events available in the Telerik Calendar for Blazor:
15
15
*[ValueChanged](#valuechanged)
16
16
*[DateChanged](#datechanged)
17
17
*[ViewChanged](#viewchanged)
18
-
*[RangeStartChanged](#rangestartchanged)
19
-
*[RangeEndChanged](#rangeendchanged)
18
+
*[RangeStartChanged and RangeEndChanged](#rangestartchanged-and-rangeendchanged)
20
19
21
20
## ValueChanged
22
21
@@ -78,31 +77,26 @@ When handling the `ViewChanged` event, you cannot use two-way binding for the `V
78
77
79
78
>tip You are not required to provide an initial value to the `View` parameter. It will default to `CalendarView.Month`.
80
79
81
-
## RangeStartChanged
80
+
## RangeStartChanged and RangeEndChanged
82
81
83
-
The `RangeStartChanged`fires every time the user selects a new starting date for the range of dates when the Calendar is in `Range` selection mode. The first click on a date in the Calendar will always be the starting date and the range can be consisted of dates only onward.
82
+
The two RangeChanged events (`RangeStartChanged`and `RangeEndChanged`) fire when the user selects a new range.
84
83
85
-
## RangeEndChanged
86
-
87
-
The `RangeEndChanged` fires after the `RangeStartChanged` with the `default` value of the model field, and every time when the selection of dates is finished.
84
+
When the user selects a range from the calendar, the first click always fires the start change with the selected date, and then clears the end of the range, so the end change event fires as well, with the default value for `DateTime` - this indicates that the end of the range is undefined. If the second click is on a date before the range start - it will become the new start.
88
85
89
86
>caption Example of `Range` Selection with `RangeStartChanged` and `RangeEndChanged` events
90
87
91
88
````CSHTML
92
89
@* Observe the behavior of the RangeStartChanged and RangeEndChanged events and adding the selected dates to a List *@
93
90
94
-
<div class="example-wrapper">
95
-
<h4>Range Selection Initial Selection</h4>
91
+
<TelerikCalendar Views="2"
92
+
Date="@Date"
93
+
SelectionMode="@CalendarSelectionMode.Range"
94
+
RangeStart="@RangeStart"
95
+
RangeEnd="@RangeEnd"
96
+
RangeStartChanged="@StartChangeHandler"
97
+
RangeEndChanged="@EndChangeHandler">
98
+
</TelerikCalendar>
96
99
97
-
<TelerikCalendar Views="3"
98
-
Date="@Date"
99
-
RangeStart="@RangeStart"
100
-
RangeEnd="@RangeEnd"
101
-
SelectionMode="@CalendarSelectionMode.Range"
102
-
RangeStartChanged="@StartChangeHandler"
103
-
RangeEndChanged="@EndChangeHandler">
104
-
</TelerikCalendar>
105
-
</div>
106
100
107
101
@if (SelectedDates.Any())
108
102
{
@@ -116,28 +110,40 @@ The `RangeEndChanged` fires after the `RangeStartChanged` with the `default` val
116
110
}
117
111
118
112
@code {
119
-
public DateTime Date { get; set; } = new DateTime(2020, 3, 1);
120
-
public DateTime RangeStart { get; set; } = new DateTime(2020, 3, 14);
121
-
public DateTime RangeEnd { get; set; } = new DateTime(2020, 3, 18);
122
-
public List<DateTime> SelectedDates { get; set; } = new List<DateTime>();
113
+
DateTime Date { get; set; } = DateTime.Now.AddDays(-5);
Copy file name to clipboardExpand all lines: components/calendar/selection.md
+74-22Lines changed: 74 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,32 +12,71 @@ position: 2
12
12
13
13
The user can select one or mode dates depending on the Calendar configuration set by the developer. They may also be forbidden selection of certain disabled dates.
14
14
15
+
This article contains the following sections:
16
+
17
+
*[Selection Mode](#selection-mode)
18
+
*[Receive User Selection](#receive-user-selection)
To control how many dates the user can select, use the `SelectionMode` property. It takes a member of the `Telerik.Blazor.CalendarSelectionMode` enum and can be:
18
27
*`Single`
19
28
*`Multiple`
20
29
*`Range`
21
30
22
-
You can pre-select a date in Single selection mode by setting the `Value` property of the calendar to the desired date.
31
+
You can pre-select a date in `Single` selection mode by setting the `Value` property of the calendar to the desired date.
23
32
24
-
To pre-select dates in the Multiple selection mode, use the `SelectedDates` property which is of type `List<DateTime>`.
33
+
To pre-select dates in the `Multiple` selection mode, use the `SelectedDates` property which is of type `List<DateTime>`.
25
34
26
-
In `Range` selection mode you can get the start and end dates of a selected range, by the user, through the `RangeStart` and `RangeEnd` parameters of type `DateTime`. You also get events `RangeStartChanged` and `RangeEndChanged`. You can read more about them and see an example in the [Events]({%slug components/calendar/events%}) article.
35
+
In `Range` selection mode you can get the start and end dates of the rangethe user selected through the `RangeStart` and `RangeEnd` parameters of type `DateTime`. You also get events `RangeStartChanged` and `RangeEndChanged`. You can read more about them and see an example in the [Events]({%slug components/calendar/events%}) article.
27
36
28
37
## Receive User Selection
29
38
39
+
The way you can get the user selection depends on the selection mode you use:
>caption Handle Single selection in the Calendar through an event
35
75
36
76
````CSHTML
37
77
@* This example shows how to handle Single selection *@
38
78
39
79
<TelerikCalendar Date="@startDate"
40
-
View="CalendarView.Month"
41
80
SelectionMode="@CalendarSelectionMode.Single"
42
81
ValueChanged="SelectionHandler">
43
82
</TelerikCalendar>
@@ -49,7 +88,6 @@ Use the `ValueChanged` event. The handler receives a `DateTime` object as parame
49
88
@code {
50
89
private DateTime SelectedDate { get; set; }
51
90
private DateTime startDate = new DateTime(2019, 5, 2);
52
-
private TelerikCalendar CalendarRef { get; set; }
53
91
54
92
public void SelectionHandler(DateTime selectedDate)
55
93
{
@@ -58,17 +96,17 @@ Use the `ValueChanged` event. The handler receives a `DateTime` object as parame
58
96
}
59
97
````
60
98
99
+
61
100
### Multiple Selection Mode
62
101
63
-
Use the `SelectedDates` property of the component reference in the `ValueChanged` handler.
102
+
With multiple selection mode, to get the user selection, use the `SelectedDates` property of the component reference in the `ValueChanged` handler.
64
103
65
104
>caption Handle Multiple selection in the Calendar
66
105
67
106
````CSHTML
68
107
@* This example shows how to handle Multiple selection *@
69
108
70
109
<TelerikCalendar Date="@startDate"
71
-
View="@CalendarView.Month"
72
110
SelectionMode="@CalendarSelectionMode.Multiple"
73
111
ValueChanged="@SelectionHandler"
74
112
@ref="@CalendarRef">
@@ -99,36 +137,51 @@ Use the `SelectedDates` property of the component reference in the `ValueChanged
99
137
````
100
138
### Range Selection Mode
101
139
102
-
Use the `RangeStart`, representing the first date of the selection, and the `RangeEnd` - the last date of the selection.
140
+
With range selection mode, you have two options to get the user choice:
141
+
142
+
* two-way binding for the `RangeStart` (representing the first date of the selection) and the `RangeEnd` (the last date of the selection) parameters.
143
+
* Handling the [RangeStartChanged and RangeEndChanged events]({%slug components/calendar/events%}#rangestartchanged-and-rangeendchanged)
144
+
103
145
104
-
>caption Handle Range selection
146
+
>caption Range selection with two-way binding
105
147
106
148
````CSHTML
107
-
@* This example shows how to handle Range selection *@
149
+
@* This example shows how to handle Range selection through two-way binding *@
108
150
109
151
<TelerikCalendar Views="2"
110
152
Date="@Date"
111
-
RangeStart="@RangeStart"
112
-
RangeEnd="@RangeEnd"
153
+
@bind-RangeStart="@RangeStart"
154
+
@bind-RangeEnd="@RangeEnd"
113
155
SelectionMode="@CalendarSelectionMode.Range">
114
156
</TelerikCalendar>
115
157
158
+
<p>
159
+
Start: @RangeStart
160
+
<br />
161
+
End: @RangeEnd
162
+
</p>
163
+
116
164
@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);
165
+
public DateTime Date { get; set; } = DateTime.Now.AddDays(-5);
166
+
public DateTime RangeStart { get; set; } = DateTime.Now.Date;
167
+
public DateTime RangeEnd { get; set; } = DateTime.Now.AddDays(15).Date;
168
+
169
+
// the RangeEnd value will be the default(DateTime) while the user is selecting a range
170
+
// that is, while they have clicked only once in the calendar
121
171
}
122
172
````
123
173
124
-
### Disabled Dates
174
+
175
+
## Disabled Dates
125
176
126
177
To prevent the user from selecting certain dates (for example, holidays), add those dates to the `DisabledDates` collection.
127
178
128
-
>caption Handle Disabled dates with Calendar Multiple selection
179
+
With `Single` and `Multiple` selection, the user can't select these dates. With `Range` selection, these dates cannot be the start or end of a range, but can be included in the range.
180
+
181
+
>caption Add Disabled dates to a Calendar with Multiple selection
129
182
130
183
````CSHTML
131
-
The user will not be able to select the first and second of April 2019.
184
+
@* The user will not be able to select the first and second of April 2019. *@
0 commit comments