This is a migrated thread and some comments may be shown as answers.

Use datafilter options to search database for matching records

3 Answers 51 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 27 Feb 2012, 11:21 PM
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





3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 02 Mar 2012, 08:45 AM
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 >>
0
Paul
Top achievements
Rank 1
answered on 02 Mar 2012, 11:03 AM
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





0
Rossen Hristov
Telerik team
answered on 02 Mar 2012, 12:29 PM
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 >>
Tags
DataFilter
Asked by
Paul
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Paul
Top achievements
Rank 1
Share this question
or