Skip to content

Commit a9f7c54

Browse files
docs(calendar): events
1 parent 8465d1d commit a9f7c54

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

components/calendar/events.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: Events
3+
page_title: Calendar for Blazor | Events
4+
description: Events in the Calendar for Blazor
5+
slug: components/calendar/events
6+
tags: telerik,blazor,calendar,events
7+
published: true
8+
position: 20
9+
---
10+
11+
# Events
12+
13+
This article explsins the events available in the Telerik Calendar for Blazor:
14+
15+
* [ValueChanged](#valuechanged)
16+
* [DateChanged](#datechanged)
17+
* [ViewChanged](#viewchanged)
18+
19+
## ValueChanged
20+
21+
The `ValueChanged` event fires when the user selects a date. To see how to handle it and to obtain the user selection, review the [Selection]({%slug components/calendar/selection%}) article.
22+
23+
## DateChanged
24+
25+
The `DateChanged` event fires when the currently shown date changes. For example, when the user [navigates]({%slug components/calendar/navigation%}) from one month to the next through the arrows.
26+
27+
When handling the `DateChanged` event, you cannot use two-way binding for the `Date` parameter. You should update it yourself in the model. If you do not, the currently shown range may revert to the original value set in the markup or to the default value.
28+
29+
````CSHTML
30+
@result
31+
<br />
32+
<TelerikCalendar Min="@min" Max="@max" Date="@initialDate" DateChanged="@DateChangedHandler">
33+
</TelerikCalendar>
34+
35+
@code {
36+
DateTime initialDate { get; set; } = DateTime.Now;
37+
DateTime min = new DateTime(2015, 1, 1);
38+
DateTime max = new DateTime(2025, 12, 31);
39+
string result { get; set; }
40+
41+
void DateChangedHandler(DateTime firstDateOfNewRange)
42+
{
43+
result = $"the user now sees a range that includes {firstDateOfNewRange}";
44+
initialDate = firstDateOfNewRange; // if you don't do this, navigating adjacent ranges will be effectively disabled
45+
}
46+
}
47+
````
48+
49+
>tip You are not required to provide an initial value to the `Date` parameter. It will default to `DateTime.Now`.
50+
51+
## ViewChanged
52+
53+
The `ViewChanged` event fires when the user changes the view they are seeing (for example, goes up from the days in the month to the months in the year).
54+
55+
When handling the `ViewChanged` event, you cannot use two-way binding for the `View` parameter. You should update it yourself in the model. If you do not, the currently shown view may revert to the original value set in the markup or to the default value.
56+
57+
````CSHTML
58+
@result
59+
<br />
60+
<TelerikCalendar Min="@min" Max="@max" View="@initialView" ViewChanged="@ViewChangedHandler">
61+
</TelerikCalendar>
62+
63+
@code {
64+
CalendarView initialView { get; set; } = CalendarView.Year;
65+
DateTime min = new DateTime(2015, 1, 1);
66+
DateTime max = new DateTime(2025, 12, 31);
67+
string result { get; set; }
68+
69+
void ViewChangedHandler(CalendarView currView)
70+
{
71+
result = $"the user now sees the {currView} view";
72+
initialView = currView; // if you don't do this, navigating views will be effectively disabled
73+
}
74+
}
75+
````
76+
77+
>tip You are not required to provide an initial value to the `View` parameter. It will default to `CalendarView.Month`.
78+
79+
## See Also
80+
81+
* [Selection]({%slug components/calendar/selection%})
82+
* [Navigation]({%slug components/calendar/navigation%})

components/calendar/overview.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ The selected date is: @selectedDate
4545
4646
![](images/basic-calendar.png)
4747

48+
>tip The `Date` parameter indicates the view the user is in. You can use its `DateChanged` event to know when the user browses through the calendar.
49+
4850
>caption Component namespace and reference
4951
5052
````CSHTML

upgrade/breaking-changes/2-0-0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ This is a list of the components that had methods removed and the new approach o
6363
### Calendar
6464

6565
* The `Navigate()` method is no longer available in favor of two-way binding for the `View` and `Date` parameters. An example is avalable in the [Navigate]({%slug components/calendar/navigation%}#programmatic-navigation) article.
66-
* The `View` and `Date` parameters should be used with two-way binding. Otherwise, state changes (like selection) may revert them to the values set in the markup and move the user unexpectedly.
66+
* The `View` and `Date` parameters should be used with two-way binding, especially when you handle `ValueChanged`. Otherwise, state changes (like selection) may revert them to the values set in the markup and move the user unexpectedly.
6767

6868
### DatePicker
6969

0 commit comments

Comments
 (0)