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

Filtering on an enum collection

1 Answer 226 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pelle
Top achievements
Rank 1
Pelle asked on 09 Dec 2010, 08:52 PM
Suppose you have the following definitions:
 
public enum Category { Spicy, Fat, Tasty, Expensive};
  
public class Dish
{
    public string Name {get; set;}
    public Category[] Categories {get; set;}
}

I show a collection of Dish objects in a RadGridView. As property Categories is a collection I concatenate the values into a single string, e.g. "Spicy, Fat". Now I would like to add some custom filtering behavior that makes it possible to this on the Categories column:
  • Show a sorted list of all the values in the Category enum (or perhaps only the values that are used by the Dish objects in the grid)
  • Use a CheckedList so that more than one value can be selected.
  • When more than one Category is used in the filter I want to see all items having at least one of the grades (i.e. an OR condition).
Example:
Grid content [Name: Categories]
- Filet Mignon: Expensive, Fat
- Sausage: Fat
- Thai Curry: Spicy, Tasty
 
If I select values Fat and Expensive I should see the rows for FiletMignon (matches both) and Sausage (matches Fat).
If I select values Spicy and Expensive I should see the rows for FiletMignon (matches Expensive) and ThaiCurry (matches Spicy).

I would be more than grateful for some help on this so thanks in advance!
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 13 Dec 2010, 12:18 PM
Hi Pelle,

Such custom filtering functionality can be achieved by implementing a Custom Filtering Control. Since you are the author of the control you can place anything inside it.

We are currently working on out-of-the-box functionality that will enable filtering on collection type properties like in your case.

Right now you cannot perform a filtering on a collection type property out -of-the-box. To do this you will have to implement the IFilterDescriptor interface and build the appropriate expression. This blog post has an example of an IFilterDescriptor implementation.

There is another solution as well. If you have the required rights, you can create a new string property on your Dish class that will actually return the concatenated categories as a string. Then in your custom filtering control you will take all checked values and build the filter string. Finally, you will set this string as the Value of the FilterDescriptor and since the column it is compared against is a string one -- filtering will work because two string will be compared.

I hope this helps.

Kind regards,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
GridView
Asked by
Pelle
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or