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

DelegateFilterDescriptor

To use a DelegateFilterDescriptor you need to create a class that implements the IFilter interface which will return the key you want to filter by. Then you can add a DelegateFilterDescriptor to the FilterDescriptors collection of the RadDataGrid and set its Filter property.

Adding a DelegateFilterDescriptor

Examples 1 and 2 demonstrate how to populate the RadDataGrid with sample data and add a DelegateFilterDescriptor.

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" Width="300" VerticalAlignment="Center"> 
        <grid:RadDataGrid.FilterDescriptors> 
            <dataCore:DelegateFilterDescriptor> 
                <dataCore:DelegateFilterDescriptor.Filter> 
                    <local:CustomFilter/> 
                </dataCore:DelegateFilterDescriptor.Filter> 
            </dataCore:DelegateFilterDescriptor> 
        </grid:RadDataGrid.FilterDescriptors> 
    </grid:RadDataGrid> 
</Grid> 
The IFilter interface contains one method - PassesFilter, which receives an instance of our custom object and the value we return determines whether the object is filtered. In that case, we filter by the number of letters in each country.

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" }, 
            new CustomData { Country = "Brazil", City = "Fortaleza" }, 
            new CustomData { Country = "Spain", City = "Malaga" }, 
            new CustomData { Country = "Bulgaria", City = "Koynare" }, 
            new CustomData { Country = "Spain", City = "Valencia" }, 
            new CustomData { Country = "Ghana", City = "Kade" }, 
            new CustomData { Country = "Brazil", City = "Porto Alegre" }, 
            new CustomData { Country = "Bulgaria", City = "Byala Slatina" }, 
            new CustomData { Country = "Brazil", City = "Joinville" }, 
        }; 
        this.grid.ItemsSource = data; 
    } 
} 
 
public class CustomData 
{ 
    public string City { get; set; } 
    public string Country { get; set; } 
} 
 
public class CustomFilter : IFilter 
{ 
    public bool PassesFilter(object item) 
    { 
        if ((item as CustomData).Country.Length < 6) 
        { 
            return true; 
        } 
        else 
        { 
            return false; 
        } 
    } 
} 

Figure 1: Result after filtering

Delegate Filter Descriptor Example

See Also

In this article
Not finding the help you need?