Skip to content

Commit 0c96b04

Browse files
svdimitrmarin-bratanov
authored andcommitted
docs(calendar): changes to Events article to showcase the RangeStartChanged and RangeEndChanged events and added example
1 parent fb54b68 commit 0c96b04

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

components/calendar/events.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ This article explains the events available in the Telerik Calendar for Blazor:
1515
* [ValueChanged](#valuechanged)
1616
* [DateChanged](#datechanged)
1717
* [ViewChanged](#viewchanged)
18+
* [RangeStartChanged](#rangestartchanged)
19+
* [RangeEndChanged](#rangeendchanged)
1820

1921
## ValueChanged
2022

@@ -76,6 +78,72 @@ When handling the `ViewChanged` event, you cannot use two-way binding for the `V
7678

7779
>tip You are not required to provide an initial value to the `View` parameter. It will default to `CalendarView.Month`.
7880
81+
## RangeStartChanged
82+
83+
The `RangeStartChanged` fires every time the user selects a new starting date for the range of dates. The first click on a date in the Calendar will always be the starting date and the range can be consisted of dates only onwards.
84+
85+
## RangeEndChanged
86+
87+
The `RangeEndChanged` fires every time when the selection of dates is finished.
88+
89+
>caption Example of `Range` Selection with `RangeStartChanged` and `RangeEndChanged` events
90+
91+
````CSHTML
92+
@* Observe the behavior of the RangeStartChanged and RangeEndChanged events and adding the selected dates to a List *@
93+
94+
<div class="example-wrapper">
95+
<h4>Range Selection Initial Selection</h4>
96+
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+
107+
@if (SelectedDates.Any())
108+
{
109+
<div class="mt-3">
110+
<h5 class="text-info">Selected dates:</h5>
111+
@foreach (var day in SelectedDates)
112+
{
113+
<p class="text-muted">@day</p>
114+
}
115+
</div>
116+
}
117+
118+
@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>();
123+
124+
public void StartChangeHandler(DateTime startDate)
125+
{
126+
RangeStart = startDate;
127+
GetDates();
128+
}
129+
130+
public void EndChangeHandler(DateTime endDate)
131+
{
132+
RangeEnd = endDate;
133+
GetDates();
134+
}
135+
136+
public void GetDates()
137+
{
138+
var datesInBetween = Enumerable.Range(0, 1 + RangeEnd.Subtract(RangeStart).Days)
139+
.Select(offset => RangeStart.AddDays(offset))
140+
.ToList();
141+
142+
SelectedDates = datesInBetween;
143+
}
144+
}
145+
````
146+
79147
## See Also
80148

81149
* [Selection]({%slug components/calendar/selection%})

0 commit comments

Comments
 (0)