Use datafilter options to search database for matching records

4 posts, 0 answers
  1. Paul
    Paul avatar
    26 posts
    Member since:
    Jan 2012

    Posted 27 Feb 2012 Link to this post

    Hi
    I was wondering if it was possible to use the datafilter to build say a customer object that could then be used as a parameter in a method call to service to return matching records.

    example:
    Customer object
    Firstname
    Lastname
    Address

    So if i could bind the empty customer object to the datafilter the user could select the properties in the customer object to use as the filter, so if they filtered on Firstname property i would have a customer object as follows:

    Firstname=Paul
    Lastname
    Address

    then i could pass this object to my service where it could give me back the records that match.  This would mean that i don't have to return all records and then filter.

    Can this be acheived using datafilter?

    Using silverlight 5 + Prism + MVVM + latest Telerik silverlight controls.

    Thanks
    Paul





  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 02 Mar 2012 Link to this post

    Hi,

    You can use RadDataFilter in its Unbound Mode. This will allow you to specify any kind of property names + types that the user will be able to choose from. Once the user has created his filtering criteria, all of the information will be stored in RadDataFilter.FilterDescriptors property. 

    RadDataFilter.FilterDescriptors contains IFilterDescriptors. They come in two varieties:

    1. Simple FilterDescriptor's -- these are the leaf nodes of the three and contain information like FirstName IsEqualTo "John", i.e. they have four properties:

    -- Member
    -- Operator
    -- Value
    -- IsCaseSensitie (makes sense for string member only).

    2. CompositeFilterDescriptor's -- these are classes which combine other IFilterDescriptors with a logical operator AND or OR. These are the ones that help you build a tree.

    So, RadDataFilter will store everything that you see on the screen in these "property bag"-kind-of-objects. From then on -- you can read this information and use it in any possible way that you find appealing.

    I hope this helps.

    Regards,
    Ross
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Paul
    Paul avatar
    26 posts
    Member since:
    Jan 2012

    Posted 02 Mar 2012 Link to this post

    Hi Ross

    Thanks for the quick reply.  I don't think I'll be able to use this for the senario that I'm thinking of.  First off the grid will still have to load all the data from the database and then filter.

    I was hoping I could bind the DataFilter to an object and then pass this object back to the database and filter/search for matching records to display in the grid.

    If I was able to do this I then wouldn't have to create a control on my search form for each property that I want the user to be able to filter/search on. There are 20 controls at the moment, not that they will all be used but atleast the user has the options.

    This would make the DataFilter control much more usable in my case.  I'm probably missing something here but wouldn't you want to filter the data before pulling it from the server/database?

    Also I'm doing this from my viewmodel so not sure how this would be done using the unbound approach.

    Anyway thanks again.
    Paul





  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 02 Mar 2012 Link to this post

    Hello,

    Here is what RadDataFilter does:

    1. It can be bound to a plain IEnumerable (for example an ObservableCollection<T>) and by internally using LINQ-to-Objects it will filter the source collection and it will provide the filtered result out through its FilteredSource property. Example

    2. It can be bound to anything that implements the IQueryable interface and it will filter this IQueryable directly. The access to the database (or anything else) will be performed by the respective LINQ Provider.
    Examples of things that implement the IQueryable interface are:

    - RadGridView.Items Example
    - RadDomainDataSource.DataView Example
    - RadDataServiceDataSource.DataView Example

    3. It can be used in its Unbound Mode and the customer can decide what to do with the information it stores in its FilterDescriptors collection.

    This is all that RadDataFilter was designed for and can actually do. 

    After you cover the links I have provided above it would be up to you to decide whether and how you can use this control in your architecture.

    Thank you for your understanding.

    Regards,
    Ross
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top