Filtering a GridView when collection is a property bag

3 posts, 0 answers
  1. Michael
    Michael avatar
    3 posts
    Member since:
    Jan 2012

    Posted 13 Jan 2012 Link to this post

    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. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2477 posts

    Posted 16 Jan 2012 Link to this post

    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 >>

  3. Michael
    Michael avatar
    3 posts
    Member since:
    Jan 2012

    Posted 16 Jan 2012 Link to this post

    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.

Back to Top