FlexGrid provides built-in filtering support with the help of column filters. However, consider a scenario where you want a filtering UI similar to the one seen in different e-commerce websites where a grid displaying the product listing shows only few attributes such as the product image, product name and product price. Although, the user is allowed to filter the product listing by many other attributes such as brand, category, price etc. It is not possible to set such kind of filters from column filters in data grid controls. Hence, this walkthrough explains how you can use the DataFilter control to filter FlexGrid content using a filtering UI similar to any online store’s website.
To create an application for filtering a car list by brand, category, and price, complete the following steps:
The following image shows a list of cars filtered by a specific brand, category and price in FlexGrid using the DataFilter control.
XAML |
Copy Code
|
---|---|
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:C1FlexGrid_DataFilter" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" x:Class="C1FlexGrid_DataFilter.MainWindow" mc:Ignorable="d" Title="DataFilter" Height="900" Width="1061.526"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="475*"/> <ColumnDefinition Width="317*"/> </Grid.ColumnDefinitions> <c1:C1FlexGrid RowDetailsVisibilityMode="Visible" Name="grid" HorizontalAlignment="Left" Margin="317,0,0,0" VerticalAlignment="Top" Height="809" Width="650" Grid.ColumnSpan="2"> <c1:C1FlexGrid.Columns> <c1:Column Header="Brand" Binding="{Binding Brand}" Width="150" /> <c1:Column Header="Model" Binding="{Binding Model}" Width="150" /> <c1:Column Header="Price" Binding="{Binding Price}" Width="150" /> <c1:Column Header="Category" Binding="{Binding Category}" Width="150" /> </c1:C1FlexGrid.Columns> <c1:C1FlexGrid.RowDetailsTemplate> <DataTemplate> <DockPanel Background="GhostWhite"> <Image DockPanel.Dock="Left" Name="img" Source="{Binding Picture}" Height="64" Margin="10" /> <Grid Margin="0, 10"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Text="Brand: " FontWeight="Bold" /> <TextBlock Text="{Binding Brand}" Grid.Column="1" /> <TextBlock Text="Model: " FontWeight="Bold" Grid.Row="1" /> <TextBlock Text="{Binding Model}" Grid.Column="1" Grid.Row="1" /> <TextBlock Text="Price: " FontWeight="Bold" Grid.Row="2" /> <TextBlock Text="{Binding Price}" Grid.Column="1" Grid.Row="2" /> </Grid> </DockPanel> </DataTemplate> </c1:C1FlexGrid.RowDetailsTemplate> </c1:C1FlexGrid> <c1:C1DataFilter Name="c1DataFilter" FilterAutoGenerating="C1DataFilter_FilterAutoGenerating" HorizontalAlignment="Left" VerticalAlignment="Top" Height="705" Width="312" Margin="0,104,0,0"/> <Image Margin="0" Stretch="Fill" Source="/CarLogo.png" HorizontalAlignment="Left" Height="192" VerticalAlignment="Top" Width="312"/> </Grid> </Window> |
Add a class 'Car' to define data.