New to Telerik UI for .NET MAUI? Start a free 30-day trial

Filtering

The DataGrid supports filtering through the UI - Filtering UI and programmatic filtering.

Filtering UI

On Mobile (iOS and Android) Filtering UI appears when clicking the options icon (OptionsButton, three dots) on each column's header and it allows the user to easily filter data by column values.

On Desktop Filtering UI appears when clicking on the filtering icon on each column's header'.

DataGrid Filtering UI

The Filtering UI exposes the following properties:

  • UserFilterMode—Defines whether the Filtering UI is enabled/disabled. The available options are Auto/Enabled/Disabled. The default value of the UserFilterMode is Auto. Set the property on DataGrid control.

  • CanUserFilter(bool) property is used to enable/disable the filtering of a specific column. Set the property to a specific column.

  • ShowDistinctValuesFilter(bool)—Defines whether the distinct values are included int he Filering UI. By default the value is true.

Events related to DistinctValuesFilter:

  • DistinctValuesLoading event—Occurs when loading the distinct values that will be displayed in the Telerik.Maui.Controls.Compatibility.DataGrid.DataGridDistinctValuesFilterView. The DistinctValuesLoading event handler receives two parameters:
    • The sender argument, which is of type object, but can be cast to the RadDataGrid type.
    • A DistinctValuesLoadingEventArgs object, which provides the following properties:
      • DistinctValues— Is a property which specifies a list of values of type IEnumerable which are to be displayed in the DataGridDistinctValuesFilterView.
      • Column— Is a readonly property of type DataGridColumn which gets the column for which the distinct values are being loaded.

FilterControl Template

The Telerik DataGrid allows you to apply filtering to the datagrid column using the FilterControlTemplate property.

  • FilterControlTemplate(DataTemplate): Specifies the user defined template used for Filtering UI. The template must contain an instance of the Telerik.XamarinForms.DataGrid.DataGridFilterControlBase class

Programmatic Filtering

Programmatic filtering is achieved by adding different filter descriptors in the FilterDescriptor collection of the control.

The following descriptor types are supported:

All FilterDescriptors are located in the Telerik.XamarinForms.Common.Data namespace:

using Telerik.XamarinForms.Common.Data;

Text Filter Descriptor

The TextFilterDescriptor supports the following properties:

  • PropertyName—Gets or sets the name of the property that is used to retrieve the filter value.
  • Operator—Gets or sets the TextOperator value that defines how the Value member is compared with each value from the items source.
  • Value—Gets or sets the value used in the comparisons. This is the right operand of the comparison.
  • IsCaseSensitive—Gets or sets a value that determines whether the text comparisons will be case-sensitive. The default value is True.

To use TextFilterDescriptor, you need to add its instance to the RadDataGrid.FilterDescriptors collection and to set its PropertyName property to associate it with the property from your custom objects. Then, through the Operator and Value properties, you need to set the filter condition and the value to compare. You can also use the IsCaseSensitive property to determine if the text comparisons will be case-sensitive or not.

<telerikCommon:TextFilterDescriptor PropertyName="Country"
                             Operator="StartsWith"
                             IsCaseSensitive="False"
                             Value="En"/>

Numerical Filter Descriptor

The NumericalFilterDescriptor represents a descriptor which filters by properties of the numerical data type.

It exposes the following properties:

  • PropertyName—Gets or sets the name of the property that is used to retrieve the filter value.
  • 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.

<telerikCommon:NumericalFilterDescriptor PropertyName="StadiumCapacity"
                                  Operator="IsLessThan"
                                  Value="80000"/>

DateTime Filter Descriptor

The DateTimeFilterDescriptor is a descriptor which filters by properties of the System.DateTime data type.

It exposes the following properties:

  • PropertyName—Gets or sets the name of the property that is used to retrieve the filter value.
  • 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.

<telerikCommon:DateTimeFilterDescriptor PropertyName="Established"
                                 Operator="IsLessThan"
                                 Value="1900/01/01"/>

TimeSpan Filter Descriptor

The TimeSpanFilterDescriptor is a descriptor which filters by properties of the System.TimeSpan data type.

It exposes the following properties:

  • PropertyName—Gets or sets the name of the property that is used to retrieve the filter value.
  • 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.

<telerikCommon:TimeSpanFilterDescriptor PropertyName="Time"
                                 Operator="IsLessThan"
                                 Value="22/11/21"/>

Boolean Filter Descriptor

The BooleanFilterDescriptor is a descriptor which filters by properties of the System.Boolean data type.

It exposes the following properties:

  • PropertyName—Gets or sets the name of the property that is used to retrieve the filter value.
  • Value—Gets or sets the value used in the comparisons. This is the right operand of the comparison.

<telerikCommon:BooleanFilterDescriptor PropertyName="IsChampion"
                                Value="true"/>

Nested Property Text Filter Descriptor

The NestedProprtyTextFilterDescriptor is a descriptor which filters the nested properties.

It exposes the following properties:

  • PropertyName—Gets or sets the name of the property that is used to retrieve the filter value.
  • Operator—Gets or sets the TextOperator value that defines how the Value member is compared with each value from the items source.
  • Value—Gets or sets the value used in the comparisons. This is the right operand of the comparison.
  • IsCaseSensitive—Gets or sets a value that determines whether the text comparisons will be case-sensitive. The default value is True.

<telerikCommon:NestedProprtyTextFilterDescriptor PropertyName="Address"
                                 Operator="Contains"
                                 IsCaseSensitive="Falses"
                                 Value="Barcelona"/>

Distinct Values Filter Descriptor

The DistinctValuesFilterDescriptor is a descriptor which filters by distinct values.

It exposes the following properties:

  • PropertyName—Gets or sets the name of the property that is used to retrieve the filter value.
  • Value—Gets or sets the value used in the comparisons. This is the right operand of the comparison.

<telerikCommon:DistinctValuesFilterDescriptor />

Composite Filter Descriptor

The CompositeFilterDescriptor represents a special FilterDescriptorBase that stores an arbitrary number of other descriptors instances. The logical AND or OR operator is applied upon all composed filters to determine the result of the PassesFilter routine.

<telerikCommon:CompositeFilterDescriptor Operator="And">
    <telerikCommon:CompositeFilterDescriptor.Descriptors>
        <telerikCommon:NumericalFilterDescriptor PropertyName="StadiumCapacity"
                                          Operator="IsGreaterThan"
                                          Value="55000"/>
            <telerikCommon:NumericalFilterDescriptor PropertyName="StadiumCapacity"
                                              Operator="IsLessThan"
                                              Value="85000"/>
    </telerikCommon:CompositeFilterDescriptor.Descriptors>
</telerikCommon:CompositeFilterDescriptor>

Delegate Filter Descriptor

The DelegateFilterDescriptor exposes the Filter property, which gets or sets the IFilter implementation used to check whether a data item passes the filter or not.

To use a DelegateFilterDescriptor, you need to create a class that implements the IFilter interface which will return the Key by which you want to filter.

Then, you need to add a DelegateFilterDescriptor to the RadDataGrid.FilterDescriptors collection and set its Filter property.

The following example demonstrates the CustomFilter implementation:

class CustomFilter : IFilter
{
    public bool PassesFilter(object item)
    {
        if ((item as Club).StadiumCapacity > 60000 && (item as Club).StadiumCapacity <85000)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

Add the DelegateFilterDescriptor to the RadDataGrid instance:

dataGrid.FilterDescriptors.Add(new DelegateFilterDescriptor() { Filter = new CustomFilter()});

See Also

In this article
Not finding the help you need?