Unbound Mode
There are scenarios, in which you might want to use RadDataFilter only for its UI without passing any data to it. This scenarios will require you to use the RadDataFilter's Unbound Mode feature. The usage of this feature consists in manually setting some of the RadDataFilter's properties and handling events.
The example in this topic will show you a RadGridView bound to a list of Employee objects. A RadDataFilter will be used as UI to filter the data, but the filtering itself will be done outside the RadDataFilter via manipulation of FilterDescriptor objects.
Here is the XAML for the example. In it you can see a RadGridView and a RadDataFilter.
<Grid x:Name="LayoutRoot"
Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<telerik:RadDataFilter x:Name="radDataFilter" />
<telerik:RadGridView x:Name="radGridView"
ItemsSource="{Binding FilteredSource, ElementName=radDataFilter}"
AutoGenerateColumns="False"
Grid.Row="1">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding CompanyName}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Title}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
When in Unbound Mode, RadDataFilter has no Source. The developer instructs it what properties to show in its drop-downs by assigning its ItemPropertyDefinitions property. This is a collection of ItemPropertyDefinition objects that contains all the information regarding the properties, their type, their attributes, etc.
Here is the code-behind for the example. In it you should take notice at the instantiation of the ItemPropertyDefinition class and the objects passed to its constructor as arguments. Also take a closer look at the code inside the event handler for the FilterDescriptors collection's CollectionChanged event. In it is implemented the actual filtering. This is done by synchronizing the FilterDescriptors collection of the RadDataFilter with the one of the RadDataGridView.
At the end of the topic you can find the code for the Employee class, used in the example.
public UnboundModeSample()
{
InitializeComponent();
ItemPropertyDefinition nameDefinition = new ItemPropertyDefinition( "Name", typeof( string ), "Employee's Name" );
this.radDataFilter.ItemPropertyDefinitions.Add( nameDefinition );
this.radDataFilter.FilterDescriptors.CollectionChanged += this.FilterDescriptors_CollectionChanged;
this.radGridView.ItemsSource = RadGridViewSampleData.GetEmployees();
}
private void FilterDescriptors_CollectionChanged( object sender, NotifyCollectionChangedEventArgs e )
{
if ( e.Action == NotifyCollectionChangedAction.Add )
{
this.radGridView.FilterDescriptors.AddRange( e.NewItems.OfType<IFilterDescriptor>() );
}
else if ( e.Action == NotifyCollectionChangedAction.Remove )
{
foreach ( var item in e.OldItems.OfType<IFilterDescriptor>() )
{
this.radGridView.FilterDescriptors.Remove( item );
}
}
}Here is also the code for the Employee class, used in the example.
public class Employee
{
public Employee( string name, string companyName, string title )
{
this.Name = name;
this.CompanyName = companyName;
this.Title = title;
}
public string Name
{
get;
set;
}
public string CompanyName
{
get;
set;
}
public string Title
{
get;
set;
}
}