Home > English > Filtering a DomainDataSource in Xaml

Filtering a DomainDataSource in Xaml

Another common feature that I use in the DomainDataSource control is the ability to filter data. You can define your filters either in XAML or programmaticallly.

Here are the available properties for a FilterDescriptor:

Name Description
IgnoredValue Gets or sets the value that is not applied to a query operation for filtering.
IsCaseSensitive Gets or sets a value indicating whether the FilterDescriptor is case sensitive for string values.
Operator Gets or sets the filter operator.
PropertyPath Gets or sets the name of the property path used as the data value to assess whether the entity meets the filter check.
Value Gets or sets the value to use for evaluating the filter condition.

The following is an example of filtering based on the value of another control:

<riaCtls:DomainDataSource 
    x:Name="ddsForms" 
    QueryName="ReturnFormsAssocaitedWithAMasterFormOnlyQuery" 
    AutoLoad="True">
    <riaCtls:DomainDataSource.DomainContext>
        <data:MyDomainContext />
    </riaCtls:DomainDataSource.DomainContext>

    <riaCtls:DomainDataSource.FilterDescriptors>
        <riaCtls:FilterDescriptor 
            PropertyPath="ApplicationId" Operator="IsEqualTo" 
            Value="{Binding ElementName=cboApplications, Path=SelectedItem.ApplicationId}" />
    </riaCtls:DomainDataSource.FilterDescriptors>
            
    <riaCtls:DomainDataSource.SortDescriptors>
        <riaCtls:SortDescriptor PropertyPath="Name" Direction="Ascending" />
    </riaCtls:DomainDataSource.SortDescriptors>

</riaCtls:DomainDataSource>

Most of the properties are self explanator but I wanted to go over the three main attributes on the FilterDescriptor object. You tell the filter what property you want it to operate on by passing in a value to the PropertyPath attribute. You tell it how to operate using the Operator attribute by choosing one of the following values:

Member name Description
IsLessThan The data value must be smaller than the filter value.
IsLessThanOrEqualTo The data value must be smaller than or equal to the filter value.
IsEqualTo The data value must be equal to the filter value.
IsNotEqualTo The data value must be different from the filter value.
IsGreaterThanOrEqualTo The data value must be larger than or equal to the filter value.
IsGreaterThan The data value must be larger than the filter value.
StartsWith The data value must start with the filter value.
EndsWith The data value must end with the filter value.
Contains The data value must contain the filter value.
IsContainedIn The data value must be contained in the filter value.

Finally, the Value attribute is what value you are going to pass to the filter.

If you want to provide a more complex criteria, you can simple do the following:

<riaCtls:DomainDataSource 
    x:Name="ddsForms" 
    QueryName="ReturnFormsAssocaitedWithAMasterFormOnlyQuery" 
    FilterOperator="And"
    AutoLoad="True">
    <riaCtls:DomainDataSource.DomainContext>
        <data:MyDomainContext />
    </riaCtls:DomainDataSource.DomainContext>

    <riaCtls:DomainDataSource.FilterDescriptors>
        <riaCtls:FilterDescriptor 
            PropertyPath="ApplicationId" Operator="IsEqualTo" 
            Value="{Binding ElementName=cboApplications, Path=SelectedItem.ApplicationId}" />
        <riaCtls:FilterDescriptor 
            PropertyPath="TagId" Operator="IsEqualTo" 
            Value="{Binding ElementName=cboTags, Path=SelectedItem.TagId}" />
    </riaCtls:DomainDataSource.FilterDescriptors>
            
    <riaCtls:DomainDataSource.SortDescriptors>
        <riaCtls:SortDescriptor PropertyPath="Name" Direction="Ascending" />
    </riaCtls:DomainDataSource.SortDescriptors>

</riaCtls:DomainDataSource>

The thing to notice is the new attribute FilterOperator. You can either do logical AND or logical OR operations. This gives you quite abit of flexibility when trying to provide your user with the flexibility of sifting through data.

I try to keep all of my behavior interactions bound to properties on my corresponding ViewModel . By exposing properties, I can use these values in other parts of my ViewModel without needing to expose the individual controls on my View. I sometimes also run into problems when I create my views dynamically and I can’t always rely on other controls being loaded or working when I want them to. Thus binding to properties seem to be the natural place for me when I want to filter my DomainDataSource.

The following is an example of binding to a ViewModel:

<riaCtls:DomainDataSource 
    x:Name="ddsForms" 
    QueryName="ReturnFormsAssocaitedWithAMasterFormOnlyQuery" 
    AutoLoad="True">
    <riaCtls:DomainDataSource.DomainContext>
        <data:MyDomainContext />
    </riaCtls:DomainDataSource.DomainContext>

    <riaCtls:DomainDataSource.FilterDescriptors>
        <riaCtls:FilterDescriptor 
            PropertyPath="ApplicationId" Operator="IsEqualTo" 
            Value="{Binding CurrentApplicationId}" />
    </riaCtls:DomainDataSource.FilterDescriptors>
            
    <riaCtls:DomainDataSource.SortDescriptors>
        <riaCtls:SortDescriptor PropertyPath="Name" Direction="Ascending" />
    </riaCtls:DomainDataSource.SortDescriptors>

</riaCtls:DomainDataSource>

Hope this helps…

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: