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

Filtering column problem

14 Answers 449 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 20 Jul 2011, 08:36 PM
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

14 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 21 Jul 2011, 06:45 AM
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!

0
Oliver
Top achievements
Rank 1
answered on 21 Jul 2011, 03:33 PM
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
0
Rossen Hristov
Telerik team
answered on 25 Jul 2011, 09:22 AM
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!

0
Nyami
Top achievements
Rank 1
answered on 04 Aug 2011, 03:47 PM
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
0
Rossen Hristov
Telerik team
answered on 05 Aug 2011, 11:53 AM
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 >>

0
Nyami
Top achievements
Rank 1
answered on 05 Aug 2011, 01:44 PM
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
0
Rossen Hristov
Telerik team
answered on 05 Aug 2011, 02:09 PM
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 >>

0
Nyami
Top achievements
Rank 1
answered on 05 Aug 2011, 02:32 PM
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
0
Rossen Hristov
Telerik team
answered on 08 Aug 2011, 08:35 AM
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 >>

0
Nyami
Top achievements
Rank 1
answered on 08 Aug 2011, 09:01 AM
Cheers Ross, 
Cheers again!
0
David Brenchley
Top achievements
Rank 1
answered on 31 Oct 2011, 11:28 PM
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
0
David Brenchley
Top achievements
Rank 1
answered on 02 Nov 2011, 07:03 PM
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.
0
Moe
Top achievements
Rank 1
answered on 02 Jul 2013, 06:09 PM
Rossen,

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

Best,
Moe
0
Rossen Hristov
Telerik team
answered on 03 Jul 2013, 07:21 AM
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 >>

Tags
GridView
Asked by
Oliver
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Oliver
Top achievements
Rank 1
Nyami
Top achievements
Rank 1
David Brenchley
Top achievements
Rank 1
Moe
Top achievements
Rank 1
Share this question
or