DateTimeRangePicker

in namespace DotVVM.BusinessPack.Controls

Renders a DateTimeRangePicker control which lets the user either to type the start date or end date, or select them from a calendar popup.

Usage & Scenarios

Renders a text field that allows the user to enter or select two date, time or date and time values using a Gregorian-style calendar popup.

Sample 1: Basic Usage

The SelectedStartDate and SelectedEndDate properties represent DateTime values with the date range selected in the control.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}" />

<p>Selected dates: <dot:Literal Text="{value: StartDate}" FormatString="g" /> - <dot:Literal Text="{value: EndDate}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);
    }
}

Sample 2: Selection Bounds

You can use the MinDate and MaxDate properties to specify the minimum and maximum values for the selection.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        MinDate="{value: MinimumDate}"
                        MaxDate="{value: MaximumDate}" />

<p>Selected dates: <dot:Literal Text="{value: StartDate}" FormatString="g" /> - <dot:Literal Text="{value: EndDate}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);
        public DateTime MinimumDate { get; set; } = DateTime.Now.AddDays(-5);
        public DateTime MaximumDate { get; set; } = DateTime.Now.AddDays(5);
    }
}

Sample 3: Modes

You can use the Mode property to determine whether you want to select Date, Time or DateTime (a combination of date and time).

Even if you are in the Time mode, the control still requires the SelectedStartDate and SelectedEndDate properties to be bound to properties of DateTime type.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        Mode="Date" />

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        Mode="Time" />

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        Mode="DateTime" />
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);
        public DateTime SelectedTime { get; set; } = DateTime.Now;
        public DateTime SelectedDateTime { get; set; } = DateTime.Now;
    }
}

Sample 4: Restrictions

If you require more granular control over what dates can be selected, you can use the Restrictions property. We currently support the following types of restrictions:

  • DayOfWeekRestriction - Allows to disable selection of a specific day of week. You can also specify the time interval you need to disable using the StartTime and EndTime properties.
  • DateRangeRestriction - Allows to disable a secific range of dates (one day, one month, etc.). You just need to set the StartDate and EndDate properties.

Restrictions can be combined with MinDate and MaxDate properties and are verified both on client-side and server-side.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        Restrictions="{value: Restrictions}" />
using System;
using DotVVM.BusinessPack.Controls;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample4
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);

        public List<CalendarRestrictionBase> Restrictions { get; set; } = new List<CalendarRestrictionBase>()
        {
            new DayOfWeekRestriction() { DayOfWeek = DayOfWeek.Saturday },
            new DayOfWeekRestriction() { DayOfWeek = DayOfWeek.Sunday },
            new DateRangeRestriction() { StartDate = DateTime.MinValue, EndDate = DateTime.Now }
        };
    }
}

Sample 5: Format Strings

The FormatString property specifies the format that will be used to display selected dates. Use standard or custom .NET date format strings.

The language of the calendar and the first day of week is specified by the request culture. You can find more info in the Globalization tutorial.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        FormatString="dd MMM yyyy"
                        Mode="Date" />

<p>Selected dates: <dot:Literal Text="{value: StartDate}" FormatString="g" /> - <dot:Literal Text="{value: EndDate}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample5
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);
    }
}

Sample 6: SelectionCompleted Event

When the user completes or changes the selection, the SelectionCompleted event is triggered.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        SelectionCompleted="{command: SelectionCompleted()}" />

<p>Date range has been changed {{value: DateSelectionsCount}} times.</p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample6
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);
        public int DateSelectionsCount { get; set; }

        public void SelectionCompleted()
        {
            DateSelectionsCount++;
        }
    }
}

Sample 7: Keep Popup Open

The ClosePopupOnSelectionComplete can keep the popup open when the date is selected. By default, the popup closes when the user finishes the date selection.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        ClosePopupOnSelectionComplete="true" />

<p>Selected dates: <dot:Literal Text="{value: StartDate}" FormatString="g" /> - <dot:Literal Text="{value: EndDate}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample7
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);
    }
}

Sample 8: Separator

The SeparatorText property allows to customize the text between the start and end date in the text field.

<bp:DateTimeRangePicker SelectedStartDate="{value: StartDate}"
                        SelectedEndDate="{value: EndDate}"
                        SeparatorText="till" />

<p>Selected dates: <dot:Literal Text="{value: StartDate}" FormatString="g" /> - <dot:Literal Text="{value: EndDate}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.DateTimeRangePicker.sample8
{
    public class ViewModel : DotvvmViewModelBase
    {
        public DateTime StartDate { get; set; } = DateTime.Now.AddDays(-1);
        public DateTime EndDate { get; set; } = DateTime.Now.AddDays(1);
    }
}

Properties

Name Type Description Notes Default Value
property icon Attributes Dictionary<String,Object>
attribute
inner element
static value
bindable
default
null
property icon AutoFocus Boolean Gets or sets whether the control should have focus when page loads or when a dialog is opened. The default value is false.
attribute
inner element
static value
bindable
default
False
property icon ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
Static
property icon ClosePopupOnSelectionComplete Boolean Gets or sets whether the popup should be hidden when the user completes the selection.
attribute
inner element
static value
bindable
default
True
property icon DataContext Object Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value.
attribute
inner element
static value
bindable
default
null
property icon Enabled Boolean Gets or sets whether the control is enabled and can be modified.
attribute
inner element
static value
bindable
default
True
property icon EndDatePlaceholder String Gets or sets the text displayed when the SelectedEndDate is empty.
attribute
inner element
static value
bindable
default
null
property icon FormatString String Gets or sets the format string that will be used to display the date.
attribute
inner element
static value
bindable
default
null
property icon ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
null
property icon InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
null
property icon MaxDate DateTime? Gets or sets the highest date that can be selected by user.
attribute
inner element
static value
bindable
default
null
property icon MinDate DateTime? Gets or sets the lowest date that can be selected by user.
attribute
inner element
static value
bindable
default
null
property icon Mode CalendarMode Gets or sets whether you want the user to pick only date, only time, or both date and time.
attribute
inner element
static value
bindable
default
Date
property icon Restrictions IEnumerable<CalendarRestrictionBase> Gets or sets days a collection of rules specifying which date time intervals can't be selected.
attribute
inner element
static value
bindable
default
null
property icon SelectedEndDate DateTime? Gets or sets the end of date-time range selected by user. It's always greater than the SelectedStartDate.
attribute
inner element
static value
bindable
default
null
property icon SelectedStartDate DateTime? Gets or sets the start of date-time range selected by user.
attribute
inner element
static value
bindable
default
null
property icon SeparatorText String Gets or sets the string which is used to separate the inputs. The default value is " - ".
attribute
inner element
static value
bindable
default
-
property icon StartDatePlaceholder String Gets or sets the text displayed when the SelectedStartDate is empty.
attribute
inner element
static value
bindable
default
null
property icon TabIndex Int32 Gets or sets the order in which the control is reachable in sequential keyboard navigation. The default value is 0 which means the document order.
attribute
inner element
static value
bindable
default
0
property icon UseFormatStringAsPlaceholder Boolean Gets or sets whether to use FormatString as a placeholder when placeholder property is not set. It is enabled by default.
attribute
inner element
static value
bindable
default
True
property icon Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description
event icon SelectionCompleted Command Gets or sets the command that is called when the user successfully selects or unselects a value.

HTML produced by the control