|
| 1 | +--- |
| 2 | +title: Header Template |
| 3 | +page_title: DateRangePicker - Header Template |
| 4 | +description: Use custom rendering in the calendar header of the Blazor DateRangePicker. |
| 5 | +slug: daterangepicker-header-template |
| 6 | +tags: telerik,blazor,daterangepicker,template |
| 7 | +published: True |
| 8 | +position: 15 |
| 9 | +--- |
| 10 | + |
| 11 | +# Header Template |
| 12 | + |
| 13 | +The `<HeaderTemplate>` allows you to customize the header of the calendar popup. If the application defines this template, the component will not render any of the built-in buttons and labels in the calendar header area. |
| 14 | + |
| 15 | +The example below is using a [DateRangePicker reference and methods]({%slug daterangepicker-overview%}#daterangepicker-reference-and-methods). |
| 16 | + |
| 17 | +>caption Header template with custom content in the DateRangePicker Calendar header |
| 18 | +
|
| 19 | +````CSHTML |
| 20 | +<TelerikDateRangePicker StartValue="@StartDate" |
| 21 | + EndValue="@EndDate" |
| 22 | + Format="dd MMMM yyyy" |
| 23 | + StartValueChanged="@( (DateTime? newStart) => StartChanged(newStart) )" |
| 24 | + EndValueChanged="@( (DateTime? newEnd) => EndChanged(newEnd) )" |
| 25 | + Min="@MinDate" Max="@MaxDate" |
| 26 | + @ref="@Picker"> |
| 27 | + <HeaderTemplate> |
| 28 | + <span> |
| 29 | + <TelerikButton OnClick="@GoToPrevious" Icon="arrow-60-left" Title="Go to Previous Month"></TelerikButton> |
| 30 | + <TelerikButton OnClick="@SelectToday">Today</TelerikButton> |
| 31 | + <TelerikButton OnClick="@GoToNext" Icon="arrow-60-right" Title="Go to Next Month"></TelerikButton> |
| 32 | + </span> |
| 33 | + <span style="padding-right: .6em;"> |
| 34 | + <TelerikIcon Icon="parameter-date-time" /> Showing |
| 35 | + <strong> |
| 36 | + @ViewDate.Month/@ViewDate.Year - @ViewDate.AddMonths(1).Month/@ViewDate.AddMonths(1).Year |
| 37 | + </strong> |
| 38 | + </span> |
| 39 | + </HeaderTemplate> |
| 40 | +</TelerikDateRangePicker> |
| 41 | +
|
| 42 | +@code { |
| 43 | + TelerikDateRangePicker<DateTime?> Picker { get; set; } |
| 44 | +
|
| 45 | + DateTime? StartDate { get; set; } = DateTime.Now; |
| 46 | + DateTime? EndDate { get; set; } = DateTime.Now.AddDays(10); |
| 47 | +
|
| 48 | + DateTime MinDate = new DateTime(1990, 1, 1, 0, 0, 0); |
| 49 | + DateTime MaxDate = new DateTime(2029, 12, 31, 0, 0, 0); |
| 50 | +
|
| 51 | + DateTime ViewDate { get; set; } = DateTime.Now; |
| 52 | +
|
| 53 | + void StartChanged(DateTime? newStart) |
| 54 | + { |
| 55 | + StartDate = newStart; |
| 56 | +
|
| 57 | + if (newStart.HasValue) |
| 58 | + { |
| 59 | + ViewDate = newStart.Value; |
| 60 | + } |
| 61 | + else |
| 62 | + { |
| 63 | + ViewDate = DateTime.Now; |
| 64 | + } |
| 65 | + } |
| 66 | +
|
| 67 | + void EndChanged(DateTime? newEnd) |
| 68 | + { |
| 69 | + EndDate = newEnd; |
| 70 | + } |
| 71 | +
|
| 72 | + void GoToPrevious() |
| 73 | + { |
| 74 | + ViewDate = ViewDate.AddMonths(-1); |
| 75 | + Picker.NavigateTo(ViewDate, CalendarView.Month); |
| 76 | + } |
| 77 | +
|
| 78 | + void SelectToday() |
| 79 | + { |
| 80 | + ViewDate = DateTime.Now; |
| 81 | + Picker.NavigateTo(ViewDate, CalendarView.Month); |
| 82 | + } |
| 83 | +
|
| 84 | + void GoToNext() |
| 85 | + { |
| 86 | + ViewDate = ViewDate.AddMonths(1); |
| 87 | + Picker.NavigateTo(ViewDate, CalendarView.Month); |
| 88 | + } |
| 89 | +} |
| 90 | +```` |
0 commit comments