Blazor DateRange Picker Component Overview

The Blazor DateRange Picker component allows the user to select a date range (start and end date) - both from a visual list (calendar) or to type it into a date input that can accept only dates. You can control the format shown in the input, and dates the user cannot select, as well as implement validation and respond to events.

Telerik UI for Blazor Ninja image

The DateRange Picker component is part of Telerik UI for Blazor, a professional grade UI library with 95+ native components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

Creating Blazor Date Range Picker

  1. Use the TelerikDateRangePicker tag to add the component to your razor page.
  2. Bind its StartValue and EndValue parameters to DateTime objects
  3. Optionally, provide custom Format, Min and Max values

Basic Date Range Picker with custom format, min and max

@StartValue?.ToString("dd MMM yyyy")
<br />
@EndValue?.ToString("dd MMM yyyy")
<br />
<TelerikDateRangePicker @bind-StartValue="@StartValue"
                        @bind-EndValue="@EndValue"
                        Format="dd MMMM yyyy"
                        Min="@Min" Max="@Max">
</TelerikDateRangePicker>

@code {
    public DateTime? StartValue { get; set; } = DateTime.Now;
    public DateTime? EndValue { get; set; } = DateTime.Now.AddDays(10);
    public DateTime Min = new DateTime(1990, 1, 1, 8, 15, 0);
    public DateTime Max = new DateTime(2025, 1, 1, 19, 30, 45);
}

Events

The Blazor Date Range Picker generates events that you can handle and further customize its behavior. Read more about the Blazor Date Range Picker events....

Validation

You can ensure that the component value is acceptable by using the built-in validation. Read more about input validation....

To restrict the user from writing dates in the input so that the end is after the start, you must implement a custom data annotation attribute (you can find an example in the article linked above). The DateRangePicker component does not do this out-of-the-box in order to provide smooth user experience - the code cannot know what the user intent is and they might fix the range if they are given the chance, so correcting the input immediately may prevent them from using it comfortably. The component can fully control the user experience in the popup calendar and it ensures there that the range values are valid (start is before the end). If the user chooses an end date before the start, this date becomes the new start and they can choose the end again.

Header Template

The DateRangePicker allows you to customize the rendering of the Calendar popup header. Learn more from the Header Template article.

Parameters

The Blazor Date Range Picker provides various parameters that allow you to configure the component. Also check the DateRangePicker's public API.

Attribute Type and Default Value Description
BottomView CalendarView
CalendarView.Month
Defines the bottommost view in the popup calendar to which the user can navigate to. Defaults to CalendarView.Month.
DebounceDelay int
150
Time in milliseconds between the last typed symbol and the value update. Use it to balance between client-side performance and number of database queries.
DisabledDates List<DateTime> Specifies a list of dates that can not be selected as the start or end of the range, see the Live Demo: Date Range Picker Disabled Dates.
Enabled bool Specifies whether typing in the input is allowed.
Format string Specifies the format of the DateInputs of the DateRangePicker. Read more about supported data formats in Telerik DateInput for Blazor UI article.
EndId and StartId string render as the id attribute on the <input /> element, so you can attach a <label for=""> to the input.
Min DateTime The earliest date that the user can select.
Max DateTime The latest date that the user can select.
StartValue and EndValue T The current values of the inputs for start and end of the range. Can be used for two-way binding.
View CalendarView Specifies the current view that will be displayed in the popup calendar.
TabIndex int? maps to the tabindex attribute of both input HTML elements in the component and them both will have the same tabindex. You can use it to customize the order in which the inputs in your form focus with the Tab key.
Placeholder string maps to the placeholder attribute of the HTML element. The Placeholder will appear if the component is bound to nullable DateTime object - DateTime?, but will not be rendered if the component is bound to the default value of a non-nullable DateTime object. The Placeholder value will be displayed when the input is not focused. Once the user focuses it to start typing, the Format Placeholder (default or customized one) will override the Placeholder to indicate the format the date should be entered in.

The date range picker is, essentially, a date input and a calendar and the properties it exposes are mapped to the corresponding properties of these two components. You can read more about their behavior in the respective components' documentation.

Styling and Appearance

The following parameters enable you to customize the appearance of the Blazor Date Range Picker:

Attribute Type and Default Value Description
Class string The CSS class that will be rendered on the main wrapping element of the Date Range Picker
PopupClass string additional CSS class to customize the appearance of the Date Range Picker's dropdown.

You can find more options for customizing the Date Range Picker styling in the Appearance article.

Format Placeholder

The FormatPlaceholder parameter allows you to set custom strings as placeholders for each DateTime segment and is available for the following Telerik UI for Blazor components:

  • DateInput
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker

To set up the FormatPlaceholder, use the <*Component*FormatPlaceholder> nested tag. It allows you to set format placeholders by using the following parameters:

  • Day
  • Month
  • Year
  • Hour
  • Minute
  • Second
  • Weekday

By default, the value for all parameters is null, which applies the full format specifier.

DateRangePicker Reference and Methods

Add a reference to the component instance to use the Date Range Picker's methods.

Method Description
Close Closes the Calendar popup.
FocusStartAsync Focuses the Date Range Picker start value textbox.
FocusEndAsync Focuses the Date Range Picker end value textbox.
NavigateTo Navigates to a specified date and view. The method expects a DateTime and CalendarView arguments.
Open Opens the Calendar popup.
Refresh Re-renders the Calendar popup.
<TelerikButton OnClick="@FocusStart">Focus Start TextBox</TelerikButton>
<TelerikButton OnClick="@FocusEnd">Focus End TextBox</TelerikButton>
<TelerikButton OnClick="@OpenPicker">Open DateRangePicker</TelerikButton>

<TelerikDateRangePicker @ref="@Picker"
                        @bind-StartValue="@StartValue"
                        @bind-EndValue="@EndValue" />

@code {
    DateTime StartValue { get; set; } = DateTime.Now;
    DateTime EndValue { get; set; } = DateTime.Now.AddDays(10);

    // the component type depends on the value type, could be also DateTime?
    TelerikDateRangePicker<DateTime> Picker { get; set; }

    async Task FocusStart()
    {
        await Picker.FocusStartAsync();
    }

    async Task FocusEnd()
    {
        await Picker.FocusEndAsync();
    }

    void OpenPicker()
    {
        Picker.Open();
    }
}

Next Steps

See Also

In this article