DateFilterDashboardItem Class
A Date Filter dashboard item that allows end users to filter other dashboard items by date-time values.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v19.1.Core.dll
Declaration
public class DateFilterDashboardItem :
DataDashboardItem,
IDateTimePeriodContext,
ISupportDateTimePeriods,
IEditNameProvider
Remarks
The Date Filter allows end users to apply filtering by date to other dashboard items. It displays a set of intervals that allow you to filter out values. You can use the Date Filter as a compact counterpart of the Range Filter dashboard item:
End-users can click the Click to set filter button to invoke the Date Picker:
Create a DateFilter Dashboard Item
To add a new Date Filter to the dashboard, create the DateFilterDashboardItem
class instance and add it to the Dashboard.Items collection.
Bind to Data
Use the DateFilterDashboardItem.Dimension property to specify a dimension that provides filter values.
Display Format
To specify the date-time value format, use the dimension’s DateTimeFormat property.
To specify a custom string displayed in the Date Picker component, use the DateFilterDashboardItem.DisplayTextPattern property. You can include placeholders in a custom string. The {0} placeholder is the interval’s start, the {1} placeholder is the interval’s end.
Filter Type
A filter can be a DateTime value, DateTime range or infinite interval before or after a specified date. Use the DateFilterDashboardItem.FilterType property to specify a filter type.
Date Picker
The DateFilter item contains a Date Picker - a button with a drop-down calendar. This button initially displays “Click to set filter”. To change the text, provide the DashboardStringId.DateFilterDatePickerButtonDefaultText localization string or handle the DashboardViewer.DashboardItemControlCreated event and subscribe to the DateFilterControl.CustomDisplayText event.
The Date Picker component can be located at the near end of the Quick Button series, at its far end, or it can be hidden. To change the Date Picker location, use the DateFilterDashboardItem.DatePickerLocation property.
Create Quick Filters
Quick Filters are buttons displayed within the DateFilter item. Each button has a DateTime range assigned to it. You can click the button to apply that range as a Date filter.
To add a quick filter, create the DateTimePeriod objects and add them to the DateFilterDashboardItem.DateTimePeriods collection.
Arrange Quick Filters
Quick filters in the DateFilter item can be arranged horizontally or vertically. The default mode is auto height, in which quick filters are displayed horizontally and the dashboard item shrinks automatically to fit the items and save space.
Use the DateFilterDashboardItem.ArrangementMode property to specify the arrangement mode.
Example
This code snippet creates a DateFilter dashboard item in code.
Note
The complete sample project How to Create a Dashboard with DateFilterDashboardItem in Code is available in the DevExpress Examples repository.
private DateFilterDashboardItem CreateDateFilterItem(DashboardExcelDataSource excelDataSource) {
DateFilterDashboardItem dateFilter = new DateFilterDashboardItem();
dateFilter.Name = string.Empty;
dateFilter.ShowCaption = false;
dateFilter.DataSource = excelDataSource;
dateFilter.Dimension = new Dimension("orderDateId", "OrderDate", DateTimeGroupInterval.DayMonthYear);
dateFilter.Dimension.DateTimeFormat.DateTimeFormat = DateTimeFormat.Short;
dateFilter.ArrangementMode = DateFilterArrangementMode.Vertical;
dateFilter.FilterType = DateFilterType.Between;
dateFilter.DatePickerLocation = DatePickerLocation.Far;
dateFilter.DateTimePeriods.AddRange(
DateTimePeriod.CreateLastYear(),
DateTimePeriod.CreateNextDays("Next 7 Days", 7),
new DateTimePeriod {
Name = DashboardWinLocalizer.GetString(DashboardWinStringId.PeriodMonthToDate),
Start = new FlowDateTimePeriodLimit {
Interval = DateTimeInterval.Month,
Offset = 0
},
End = new FlowDateTimePeriodLimit {
Interval = DateTimeInterval.Day,
Offset = 1
}
},
new DateTimePeriod {
Name = "Jul-18-2018 - Jan-18-2019",
Start = new FixedDateTimePeriodLimit {
Date = new DateTime(2018, 7, 18)
},
End = new FixedDateTimePeriodLimit {
Date = new DateTime(2019, 1, 18)
}
}
);
return dateFilter;
}