Skip to content

Commit 3b80bcc

Browse files
author
KB Bot
committed
Added new kb article calendar-kb-customize-multiview-header
1 parent 3d80e62 commit 3b80bcc

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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, ui, blazor, calendar, multiview, customization, header, template
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+
I want to customize the header of a MultiView Calendar to display the month name above each 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:
30+
31+
>caption MultiView Calendar with Header Template.
32+
33+
````CSHTML
34+
@using System.Globalization;
35+
36+
<style>
37+
.my-header {
38+
inline-size: var(--INTERNAL--kendo-calendar-view-width, 256px);
39+
display: flex;
40+
justify-content: center;
41+
}
42+
</style>
43+
44+
<TelerikCalendar @bind-Date="@StartDate" Views="@ViewCount"
45+
@bind-Value="@Value"
46+
@bind-View="@View"
47+
SelectionMode="@CalendarSelectionMode.Single"
48+
@ref="CalendarRef">
49+
<HeaderTemplate>
50+
@for (int i = 0; i < ViewCount; i++)
51+
{
52+
var monthNumber = Value.Month + i > 12 ? (Value.Month + i) % 12 : Value.Month + i;
53+
var month = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(monthNumber);
54+
<div class="my-header">@month</div>
55+
}
56+
</HeaderTemplate>
57+
</TelerikCalendar>
58+
59+
@code {
60+
private int ViewCount = 4;
61+
private DateTime StartDate = DateTime.Today;
62+
private DateTime Value = DateTime.Today;
63+
private CalendarView View = CalendarView.Month;
64+
private TelerikCalendar CalendarRef { get; set; }
65+
66+
private string GetMeetingClass(DateTime date)
67+
{
68+
if (date.Day % 5 == 0)
69+
{
70+
return "meeting";
71+
}
72+
else if (date.Day % 9 == 0)
73+
{
74+
return "cocktail";
75+
}
76+
else
77+
{
78+
return "";
79+
}
80+
}
81+
82+
private void NavigateToCurrentMonth()
83+
{
84+
CalendarRef.NavigateTo(DateTime.Today, CalendarView.Month);
85+
}
86+
87+
private void GoToCenturyView()
88+
{
89+
View = CalendarView.Century;
90+
}
91+
}
92+
````
93+
94+
## See Also
95+
96+
- [Calendar Overview](https://docs.telerik.com/blazor-ui/components/calendar/overview)
97+
- [Calendar Header Template](https://docs.telerik.com/blazor-ui/components/calendar/templates/header-template)
98+
- [Calendar Views](https://docs.telerik.com/blazor-ui/components/calendar/views)

0 commit comments

Comments
 (0)