Filtering column problem

15 posts, 0 answers
  1. Oliver
    Oliver avatar
    263 posts
    Member since:
    Feb 2011

    Posted 20 Jul 2011 Link to this post

    Hi,

    in my RadGridView I have multiple columns and for all columns the IsFilterable property is set to true. Actually, for all columns who have a DataMemberBinding, the filtering icon are missing.

    Thank's
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 21 Jul 2011 Link to this post

    Hello Oliver,

    What are the types that you are trying to filter on? Are they complex types?

    I have attached a simple sample project. Could you please either modify it so it reproduces the behavior you are faced with or create a one of your own and send it to us. We will take a look to see what is going on.

    Thanks in advance.

    Greetings,
    Ross
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WPF is Visual Studio 2017 Ready
  4. Oliver
    Oliver avatar
    263 posts
    Member since:
    Feb 2011

    Posted 21 Jul 2011 Link to this post

    Hi,

    first, the columns consist of and array of multiple values and the converter
    format all the values one one line as the following: Value1, Value2, Values3, etc...

    Thank's
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Jul 2011 Link to this post

    Hello Oliver,

    There is no way to filter a column which is of this type. The easiest way to do this, would be to create a new read-only string property on your business object / ViewModel and make this string property return the concatenated values. Then bind the column to this string property and you will get normal string filtering. There is no other way to achieve what you are trying to do.

    I hope this helps.

    Greetings,
    Ross
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. Nyami
    Nyami avatar
    5 posts
    Member since:
    Sep 2010

    Posted 04 Aug 2011 Link to this post

    I had a similar problem to Oliver but the solution of adding text a property to the object/view model wasn't ideal for us (our grid columns are dynamic so we have n columns in our grid which are based on a list) and when someone says it cant be done I'm up for the challenge!

    I remembered spotting a couple of things on the forum (custom filtering and expression grouping) which made me think it must be possible to achieve filtering on a column that's bound to a list using similar tactics. So after a bit of hacking about I've adapted the original solution posted by Ross and have the foundations of a solution. For the interested here's what I did:

    I updated the the Player object so that a player can now play a number of positions, this is bound to the column and a converted used show a comma delimited list in the grid cell.

    I then created a custom filter control (implementing the IFilteringControl interface) which will allow us to perform some fairly basic filtering and set this to the column's filtering control.

    <telerik:GridViewDataColumn UniqueName="myCol" DataMemberBinding="{Binding Positions, Converter={StaticResource PositionConverter}}">
        <telerik:GridViewDataColumn.FilteringControl>
            <my:EnumListFilteringControl/>
        </telerik:GridViewDataColumn.FilteringControl>
    </telerik:GridViewDataColumn>

    I then needed to make the column think it was filterable so it will show our custom filter control, unfortunately the above alone wasn't enough. To do this we need to override the DataType property of the column on the Loaded event of the grid:

    var myCol = grid.Columns["myCol"] as GridViewDataColumn;
    if (myCol != null)
    {
        // make sure we can filter on our column
        myCol.IsFilterable = true;
     
        // make sure we can group or sort, this will cause us problems just now..
        myCol.IsGroupable = false;
        myCol.IsSortable = false;
     
        // need to make the column think its a string of we'll not get the filter button..
        myCol.DataType = typeof(string);
    }

    Now for the magic, inspired by the expression group descriptor example I found on the forum I created an ExpressionFilterDescriptor which allows us to build an expression to filter the Player's positions:

    public class ExpressionFilterDescriptor<TElement> : FilterDescriptor
    {
        public Expression<Func<TElement, bool>> FilterExpression { get; set; }
         
        public override Expression CreateFilterExpression(Expression instance)
        {
            return ParameterRewriter.Rewrite(this.FilterExpression, (ParameterExpression)instance);
        }
    }

    This is then used in the View Model of the custom filter control to build a simple expression which is then used by the grid to filter the data.

    The updated solution can be found below, its not very tidy and will need to be made more generic before I can use it in my project but hopefully it will help a few folk out and give you a head start in your own solution, there is also a feature where the filter control doesn't load the list first time but toggling the filter will get round this.

    http://nyami.rakhama.com/RadGridView-WPF-FilterOnList.zip

    Cheers
    Doug
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 05 Aug 2011 Link to this post

    Hi Doug,

    This is simply brilliant. I have updated your account with Telerik points.

    With your permission, can we create a code library with your project?

    Regards,
    Ross
    the Telerik team

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

  8. Nyami
    Nyami avatar
    5 posts
    Member since:
    Sep 2010

    Posted 05 Aug 2011 Link to this post

    Cheers, feel free to ask if you want an address to send a Telerik .net Ninja stress ball to as well ;)

    Of course, please use anything from the project that will help, I'm sure you'll be able to work out whats going on.

    I had meant to add to my previous post that the expression filter can also be used for pretty much any expression on a list item, for example if you had a method that worked out if a player has talent you could use the filter below.

    var filter = new ExpressionFilterDescriptor<Player>{
        FilterExpression = p => PlayerHasTalent(p)
    };
     
    grid.FilterDescriptors.Add(filter);

    Cheers
    Doug
  9. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 05 Aug 2011 Link to this post

    Hi Doug,

    I have totally forgotten about the FilterDescriptor<T> that we provide out-of-the-box.

    The FilterDescriptor<T> allows you to directly plug a predicate that determines which items are filtered. You just need to set a lambda to the FilteringExpression property like so:

    var descriptor = new FilterDescriptor<Employee> { FilteringExpression = e => prospects.Contains(e) };
    where 'prospects' is a collection of Employees.

    I suppose that we have created the same thing. Thinking alike is definitely a good thing.

    Anyway, I will definitely ask the marketing guys for the stress ball :)

    I will let you know when they answer.

    Cheers!

    Best wishes,
    Ross
    the Telerik team

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

  10. Nyami
    Nyami avatar
    5 posts
    Member since:
    Sep 2010

    Posted 05 Aug 2011 Link to this post

    Oh yeah, I didn't spot that when I scanned through the help first time, looks like the only magic for this is setting the DataType of the column to string to make the column think it can be filtered.

    Having checked the help again I've spotted the generic SortDescriptor and GroupDescriptor which will help with the next challenge.

    Doug
  11. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 08 Aug 2011 Link to this post

    Hi Doug,

    Can you please give me a shipping address and a desired t-shirt size?

    Greetings,
    Ross
    the Telerik team

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

  12. Nyami
    Nyami avatar
    5 posts
    Member since:
    Sep 2010

    Posted 08 Aug 2011 Link to this post

    Cheers Ross, 
    Cheers again!
  13. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 31 Oct 2011 Link to this post

    Hey Doug,
    This solution is exactly what I'm looking for, but the zip file on your site appears invalid.  Do you have a valid zip for this, or has the telerik team cleaned it up and have their own solution available?

    Thanks
  14. David Brenchley
    David  Brenchley avatar
    67 posts
    Member since:
    Jun 2010

    Posted 02 Nov 2011 Link to this post

    Nevermind, I have a working solution. 

    The issue I have now is the filter indicator shows the column as being filtered, except when you scroll the column out of sight and then back in sight, the filter indicator no longer shows the column as being filtered.
  15. Moe
    Moe avatar
    1 posts
    Member since:
    Jul 2013

    Posted 02 Jul 2013 Link to this post

    Rossen,

    Have you, or the Telerik team, assembled a sample of this solution?  Doug's example appears to be unreachable.

    Best,
    Moe
  16. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 03 Jul 2013 Link to this post

    Hello Nyami,

    Since this conversation is two years old, can you please define your exact problem/task in greater detail?

    You can even open a new forum thread or support ticket, which will be much better since we try to isolate issues from one another and not mix them together.

    Thank you.

    Kind regards,
    Rossen Hristov
    the Telerik team

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

Back to Top
UI for WPF is Visual Studio 2017 Ready