Skip to content

Commit 073d6ea

Browse files
github-actions[bot]KB Botdimodi
authored
Merge new-kb-calendar-kb-customize-multiview-header-8ae51e1ab6ac48df9e18d71ed4e57bbe-2625 into production (#2635)
* Added new kb article calendar-kb-customize-multiview-header * Polish KB * Update knowledge-base/calendar-kb-customize-multiview-header.md --------- Co-authored-by: KB Bot <[email protected]> Co-authored-by: Dimo Dimov <[email protected]>
1 parent 5a53a90 commit 073d6ea

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Customize Month Headers in MultiView Calendar
3+
description: Learn how to display the month name above each view in a MultiView Calendar using a custom header template and CSS in Telerik UI for Blazor.
4+
type: how-to
5+
page_title: How to Customize Month Headers in Telerik UI for Blazor MultiView Calendar
6+
slug: calendar-kb-customize-multiview-header
7+
tags: telerik, blazor, calendar, multiview
8+
res_type: kb
9+
ticketid: 1672888
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Calendar for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
How to customize the header of a MultiView Calendar to display the month name above each month view?
26+
27+
## Solution
28+
29+
To display the month name above each view in a MultiView Calendar, use the [`HeaderTemplate`]({%slug calendar-templates-header%}) of the TelerikCalendar and apply custom CSS for styling for label positioning. The following example demonstrates how to achieve this customization. Note that the suggested approach is applicable only for `Horizontal` Calendar `Orientation`.
30+
31+
>caption MultiView Calendar with Header Template.
32+
33+
````CSHTML
34+
@using System.Globalization
35+
36+
<TelerikCalendar @bind-Date="@CalendarDate"
37+
SelectionMode="@CalendarSelectionMode.Single"
38+
@bind-Value="@CalendarValue"
39+
@bind-View="@CalendarView"
40+
Views="@ViewCount">
41+
<HeaderTemplate>
42+
<div class="month-names">
43+
@for (int i = 0; i < ViewCount; i++)
44+
{
45+
int monthNumber = CalendarValue.Month + i > 12 ? (CalendarValue.Month + i) % 12 : CalendarValue.Month + i;
46+
string month = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(monthNumber);
47+
48+
<div>@month</div>
49+
}
50+
</div>
51+
</HeaderTemplate>
52+
</TelerikCalendar>
53+
54+
<style>
55+
.month-names {
56+
width: 100%;
57+
display: flex;
58+
justify-content: space-between;
59+
60+
}
61+
.month-names > div {
62+
flex: 1 1 auto;
63+
text-align: center;
64+
}
65+
</style>
66+
67+
@code {
68+
private int ViewCount { get; set; } = 3;
69+
private DateTime CalendarDate { get; set; } = DateTime.Today;
70+
private DateTime CalendarValue { get; set; } = DateTime.Today;
71+
private CalendarView CalendarView { get; set; } = CalendarView.Month;
72+
}
73+
````
74+
75+
## See Also
76+
77+
* [Calendar Overview](https://docs.telerik.com/blazor-ui/components/calendar/overview)
78+
* [Calendar Header Template](https://docs.telerik.com/blazor-ui/components/calendar/templates/header-template)
79+
* [Calendar Views](https://docs.telerik.com/blazor-ui/components/calendar/views)

0 commit comments

Comments
 (0)