WinUI | ComponentOne
Controls / DataFilter / Types of Filters
In This Topic
    Types of Filters
    In This Topic

    The DataFilter control supports different kinds of filters namely, RangeFilter, DateFilter, NumericFilter, FullTextFilter, DateRangeFilter, ChecklistFilter etc., to filter different types of data. Corresponding to each filter, an accordion tab is added to the DataFilter control which contains the controls used to filter the data-aware control by a specific field. For example, 

    When the AutoGenerateFilters property of the C1DataFilter class is set to true, filters are automatically generated depending on the type of the fields present in the DataSource. These filters are added to the FilterCollection and can be accessed using Filters property of the C1DataFilter class.

    The following figure shows the types of filters in the DataFilter control.

    The following code demonstrates how filters can be generated programmatically in the DataFilter control.

    XAML
    Copy Code
    <Grid Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="400" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <c1:C1DataFilter x:Name="c1DataFilter" AutoGenerateFilters="False" VerticalAlignment="Top">
                <c1:C1DataFilter.Filters>
                    <c1:TextFilter PropertyName="Model" />
                    <c1:DateFilter PropertyName="DateProductionLine" HeaderText="Date Production Line" />
                    <c1:NumericFilter PropertyName="MPG_City" Increment="1" />
                    <c1:FullTextFilter PropertyName="Brand" HeaderText="Brand" />
                    <c1:RangeFilter x:Name="rangeFilter" PropertyName="Price" Maximum="370485" Minimum="12565" Increment="1000"  HeaderText="Price"/>
                </c1:C1DataFilter.Filters>
            </c1:C1DataFilter>
            <grid:FlexGrid Grid.Column="1" AutoGenerateColumns="True" x:Name="flexGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        </Grid>
    </Grid>
    

    You can connect different filters with the list of cars using the following code:

    C#
    Copy Code
    private string _fileName = "Expressions.xml";
    private DataTable _carsTable;
    public MainWindow()
    {
        this.InitializeComponent();
        //Get Cars list
        _carsTable = DataProvider.GetCarTable();
        var data = new C1DataCollection<Car>(DataProvider.GetCarDataCollection(_carsTable));
        c1DataFilter.ItemsSource = data;
        flexGrid.ItemsSource = data;
    }
    

    Reset Filters

    DataFilter also supports filter reset feature. This enables you to the reset the filter selection to its default value on the click of the button.

    As shown in the GIF below, the criteria set in the corresponding filter is cleared after clicking on the Reset Filter button.

    Data Filter UI Reset

    You can use the following code in the Click event of button to reset the filter to its default value:

    C#
    Copy Code
    private async void BtnResetFilter_Click(object sender, RoutedEventArgs e)
     {
       c1DataFilter.LoadFilterExpression(_fileName);
       await c1DataFilter.ApplyFilterAsync();
     }