FlexReport for .NET | ComponentOne
Reports in WPF / Filter Data
In This Topic
    Filter Data
    In This Topic

    Filtering allows you to extract specific subsets of data that meet certain criteria. This is essential when you only need to view or work with a portion of the data that is relevant. Filtering helps in exploring and analyzing data more effectively by focusing on specific attributes or conditions. For example, filtering customer data based on location or purchase behavior can provide insights for targeted marketing strategies.

    In FlexReport, the data is filtered by using the Filter property of the DataSource class. Using a filter is similar to specifying a WHERE clause in the SQL statement. Suppose you want to know how many times a product is available in the loaded report using the product id (Pid) of the product. You need to add the following code to Filter the product detail corresponding to the product id.

    1. In XAML view, add a Label, TextBox, Button and a  FlexViewer  control.
    2. Set the Name property of the FlexViewer control to flexfilterviewer and  Button control to btnfilter.  Also, set the Content property of the Button control to Filter Report using Product ID and Lebel control to Enter Product ID , as shown in the following code snippet:
      CS
      Copy Code
      <c1:C1FlexViewer Name="flexfilterviewer" HorizontalAlignment="Left" Height="633" VerticalAlignment="Top" Width="958" Margin="0,28,0,0"/>
      <Button x:Name="btnfilter" Content="Filter Report using Product ID" Click="btnfilter_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="171"  Margin="300,5,0,0"/>
      <TextBox x:Name="txtpid" HorizontalAlignment="Left" Margin="150,5,0,0" VerticalAlignment="Top" Width="121"></TextBox>
      <Label Content="Enter Product ID:" HorizontalAlignment="Left" VerticalAlignment="Top" Width="121"  Margin="43,0,0,0"/>
      
    3. Add the code in the code-behind file to load the report as done in the Data Binding.
    4. Create a method with the name GetMyDataTable that returns a datatable as done in the Data Binding.
    5. Add the following code in the Click event of the Button control for filtering the data in the report. In the code, the Filter property filters the data on the basis of value entered by the user in the textbox control.
      CS
      Copy Code
      flexReport.DataSource.Filter = "PiD ='" +txtpid.Text+"'";
      flexReport.Render();    
      
    6. Run the application to view the report in the flexfilterviewer control.
    7. Enter product id (Pid) ='P001' in the textbox control.
    8. Click the Filter Report using Product ID button to filter the data in the report. The records related to the product with Pid = 'P001' gets displayed in the report.

      FilterData