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

RadGridView Distinct Filter Values

5 Answers 521 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bryant
Top achievements
Rank 1
Bryant asked on 04 Nov 2011, 08:54 PM
I am using a RadGridView, with two setups.  RadDataServiceDataSource and VirtualQueryableCollectionView.

My preference is the VQCV, slick interface and all.  I have written some custom filtering controls, and implemented them (search box on freeform text columns) and date range on date time columns.  I used the following as a guide.

http://blogs.telerik.com/silverlightteam/posts/10-12-11/odata-support-in-radgridview-for-silverlight-and-wpf-the-netflix-catalog.aspx

I am stuck trying to build a filter consisting of two list boxes with drag and drop multi value filtering.  I have it setup and working if I manually put the entries in the list box.  It works great.  What I want is a way to get the distinct values to populate anytime the VQCV is updated.  i.e. if another column is filtered I want my list box values to change, cascading filtering essentially.

I have seen examples for raddomaindatasource and MVVM, just not with ODATA and either of the two datasources I mentioned earlier.

5 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 07 Nov 2011, 12:38 PM
Hello Bryant,

Since you mentioned that you are using Custom Filtering Controls, you can populate the list of distinct values with anything that you want in the Prepare method of the control. The Prepare method will be called each time the user clicks the filtering funnel in order to prepare the control for display. This is the place where you can initialize everything including your distinct values lists.

To get the distinct values from your data source you can use the Select(), Distinct(), and Where() methods that the .NET Framework provides, which is exactly what RadGridView does internally by default. However, implementing the specific logic that will retrieve your distinct values is beyond the scope of Telerik support.

Kind regards,
Ross
the Telerik team

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

0
Bryant
Top achievements
Rank 1
answered on 07 Nov 2011, 03:59 PM
Tried a reply that didn't show up.  Sorry if this is a duplicate.

Thanks for the response.  The prepare method is exactly what I was looking for on how to set the filter for distinct values.  The issue now is that when I query my service it will return distinct values, for the entire data service.  How do I pass in the current filter descriptors for my entire VQVC.  

i.e. if I have a getdistinctvalues(string propertyName) on my odata service that looks like this:

            List<string> list = CurrentDataSource.PunchListItems.Select(propertyName).OfType<string>().Distinct().ToList<string>();

How do I retrieve and pass the current set of filters from VQVC in the prepare method in order to filter the set of distinct values?
0
Rossen Hristov
Telerik team
answered on 07 Nov 2011, 04:06 PM
Hi Bryant,

That would be up to you. For example, you can pass the instance of the VQCV.FilterDescriptors to the constructor of your FilteringControl and store it in a field or something like this. Or you can do it in any other way that you can think of.

That is really a general .NET question and is beyond the scope of Telerik support.

Greetings,
Ross
the Telerik team

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

0
Bryant
Top achievements
Rank 1
answered on 07 Nov 2011, 07:24 PM
Sorry if I am missing something simple, and let me know if a support ticket would be more appropriate.

I am not asking how do I process the filters or how to incorporate into that select statement.  I am just using that so you understand what I want to do.  Your statement of just use VQVC.Filterdescriptors is EXACTLY what I need help with.  VQVC is a telerik entity and I am using custom filters on your grid, so I don't feel as though the following question is a .NET questions.

The grid is calling the constructor on my custom filter controls.  I do not do that so how would I pass in a reference to the VQVC, or how would I get a reference to it in the prepare method.  Am I thick and it is as simple as:

this.VQVC or this.DataContext.VQVC???

Thanks in advance
0
Rossen Hristov
Telerik team
answered on 08 Nov 2011, 09:59 AM
Hello Bryant,

Can you try the following (assuming the VQCV is the ItemsSource of the grid): 

public override void Prepare(Telerik.Windows.Controls.GridViewBoundColumnBase column)
{
    var grid = column.DataControl;
    var vqcv = grid.ItemsSource as VirtualQueryableCollectionView;
    var filterDescriptors = vqcv.FilterDescriptors;
}

This should solve the problem?

Just for the record, the grid is not the one that is calling the constructor of your filtering control. In fact you are calling it and then assigning it to the FilteringControl property of the column. Well, sort of. You don't actually see this because you are probably doing this in XAML, but if you were to do the same thing in code-behind it would look like this:

column.FilteringControl = new MyCustomFilteringControl();

Same thing in XAML would look something like this (pseude-code)

<column>
<column.FilteringControl>
<local:MyCustomFilteringControl/>
</column.FilteringControl>
</column>

However, when defining it in XAML it has to have a default constructor which is then called by the XAML parser. So you can only call non-default constructors in code-behind.

But please use the Prepare method approach that I have described in the beginning of the post.

Let me know if this does not help.

Greetings,
Ross
the Telerik team

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

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