New to Telerik UI for WinUI? Download free 30-day trial

DateTimeFilterDescriptor

DateTimeFilterDescriptor is a descriptor which filters by a property of type DateTime.

Properties

  • PropertyName: Gets or sets the name of the property that is used to retrieve the value to filter by.
  • Value: Gets or sets the value used in the comparisons. This is the right operand of the comparison.
  • Operator: Gets or sets the NumericalOperator value that defines the boolean logic behind the left and right operand comparison.

Adding a DateTimeFilterDescriptor

Example 1 demonstrates how to leave only the objects, whose Founded property (which is of type System.DateTime) is less than (before) 1600/01/01.

Example 1: Adding the RadDataGrid in xaml

<Grid xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid" 
     xmlns:dataCore="using:Telerik.Data.Core"> 
    <grid:RadDataGrid x:Name="grid" VerticalAlignment="Center"> 
        <grid:RadDataGrid.FilterDescriptors> 
            <dataCore:DateTimeFilterDescriptor PropertyName="Founded" 
                                               Operator="IsLessThan" 
                                               Value="1600/01/01"/> 
        </grid:RadDataGrid.FilterDescriptors> 
        <grid:RadDataGrid.Commands> 
            <local:CustomGenerateColumnCommand/> 
        </grid:RadDataGrid.Commands> 
    </grid:RadDataGrid> 
</Grid> 
Example 2 shows how to populate the RadDataGrid and use the GenerateColumn command to format the DateTime values.

Example 2: Populating the RadDataGrid

public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
        this.InitializeComponent(); 
 
        List<CustomData> data = new List<CustomData> 
        { 
            new CustomData { Country = "Brazil", City = "Caxias do Sul", Founded = new DateTime(1890,6,20) }, 
            new CustomData { Country = "Brazil", City = "Joinville", Founded = new DateTime(1851,3,9) }, 
            new CustomData { Country = "Colombia", City = "Cali", Founded = new DateTime(1536,7,25) }, 
            new CustomData { Country = "Colombia", City = "Bogota", Founded = new DateTime(1538,8,6) }, 
            new CustomData { Country = "Brazil", City = "Fortaleza", Founded = new DateTime(1726,4,13) }, 
            new CustomData { Country = "Brazil", City = "Porto Alegre", Founded = new DateTime(1772,3,26) }, 
        }; 
        this.grid.ItemsSource = data; 
    } 
} 
 
public class CustomData 
{ 
    public string Country { get; set; } 
 
    public string City { get; set; } 
 
    public DateTime Founded { get; set; } 
} 
 
public class CustomGenerateColumnCommand : DataGridCommand 
{ 
    public CustomGenerateColumnCommand() 
    { 
        this.Id = CommandId.GenerateColumn; 
    } 
 
    public override bool CanExecute(object parameter) 
    { 
        var context = parameter as GenerateColumnContext; 
        // put your custom logic here 
        return true; 
    } 
 
    public override void Execute(object parameter) 
    { 
        var context = parameter as GenerateColumnContext; 
        // put your custom logic here  
        if (context.PropertyName == "Founded") 
        { 
            DataGridTextColumn column = new DataGridTextColumn(); 
            column.CellContentFormat = "{0: yyyy/MM/dd}"; 
            context.Result = column; 
        } 
        else 
        { 
            context.Result = new DataGridTextColumn(); 
        } 
    } 
} 

Figure 1: RadDataGrid before and after filtering

DateTimeFilterDescriptor example

See Also

In this article
Not finding the help you need?