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

Filtering a GridView when collection is a property bag

2 Answers 32 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 13 Jan 2012, 04:39 PM
We're using a grid to display the results of several different queries, each with different columns.
The Data arrives to the grid as an object (Product) with an Attributes collection. We use a predefined Layout to pull the properties one by one from the bag, and a Converter function that converts the Attribute to a String.

Now, of course, our client want to be able to Filter the view based on any of the columns. Unfortunately, the filter is always applied not against the column of the view but against the Product object itself. I actually created a implicit conversion operator from Product to DateTime (which looked into the property bag & returned the Modified Date) which actually allows you to filter the grid on Modified Date.
Obviously, that's not the solution.

I then attempted to grab the OnFiltering event and FilterDescriptions and convert them to a Predicate, but again, Predicates require a named property of the Object to apply.

We were actually able to add sorting by trapping the Sorting Event and reordering the list ourselves. I could do something like that, but I am afraid I'll only be able to apply one filter at a time if I don't use the built-in Filtering.

Any suggestions or examples?

2 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 16 Jan 2012, 09:22 AM
Hi,

IValueConverters are used solely for UI display purposes. Data operations such as filtering are always performed on the raw data, i.e. what the column is actually bound to.

For the upcoming Q1 2012 we plan to add filtering support for our GridViewExpressionColumn. So one possible solution would be to use an expression column where the expression would be one that returns the actual property instead of the whole Product object.

Another solution would be to wrap your Product in a ViewModel which exposes "normal" properties and then bind the grid to a collection of such view models. In this way, everything will work out-of-the-box.

The third option that you have would be to create a custom filtering control which will know how to filter the data.

Since I am not sure what your business object looks like and how exactly are you reading properties from this property bag, if you can send me a dummy mock up project mimicking your real one, I will take it and try to implement a solution with our unofficial binaries which will be released with Q1 2012. In this way we can determine whether your scenario will be supported once we release Q1.

In particular, I need to have a real example of this thing: "The Data arrives to the grid as an object (Product) with an Attributes collection. We use a predefined Layout to pull the properties one by one from the bag, and a Converter function that converts the Attribute to a String. "

I am looking forward to hearing form you.

Kind regards,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael
Top achievements
Rank 1
answered on 16 Jan 2012, 05:58 PM
IValueConverters are used solely for UI display purposes. Data operations such as filtering are always performed on the raw data, i.e. what the column is actually bound to. 
Right, that's the thing: the column *isn't* bound. At least, not in the normal way. Here's the binding declaration from the GridViewDataColumn object initializer:
DataMemberBinding = new Binding()
{
     Converter = new AttributeToColumnConverter(),
     ConverterParameter = attributeMetadata
},
Notice, there's no Path. The Converter handles the data display as a string, it has a series of conditionals to handle getting a string value to display from various CRM data types.

Due to a customer deadline, and really the need for filtering to only work on one view, we have created a custom object to serve as the data context & do "normal" binding, which means we get the out-of-the-box sorting & filtering.

I *tried* to write a custom filtering control per this description, but got nowhere without the column actually being *bound* to anything. The Path property is just an empty string.

If I had a chance to start over, I'd use the dynamic binding described here: 
http://blogs.telerik.com/vladimirenchev/posts/11-09-28/dynamic-binding-for-your-silverlight-applications.aspx  I'm thinking binding the incoming property bag to a dynamic object would solve my problem, but I hadn't ever had a reason to use dynamics before, so it didn't occur to me until I was too far down the road.

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Michael
Top achievements
Rank 1
Share this question
or