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

GridView Filtering DomainDataSource

3 Answers 147 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Greek1
Top achievements
Rank 1
Greek1 asked on 17 Jun 2010, 08:55 AM
I have a GridView bound to a DomainDataSource.   I want to filter the records based on who is logged in.... so I added the filter like so.

   ColumnFilterDescriptor recruiterColumnFilter = new ColumnFilterDescriptor((IDataFieldDescriptor)this.rgvCandidates.Columns["Recruiter"]);  
            recruiterColumnFilter.FieldFilter.Filter1.Operator = Telerik.Windows.Data.FilterOperator.Contains;  
            recruiterColumnFilter.FieldFilter.Filter1.Value = "Kev";  
            this.rgvCandidates.FilterDescriptors.Add(recruiterColumnFilter); 

When I ran SQL profiler I noticed that the query was returning everything and the filtering was happening all client-side.  I would like the grid to be filtered and have the filter symbol highlighted on the column....but I only want to retrieve the records needed.  If the filter is cleared on the gridView then go and retreive all the records.  I'm not sure this is possible but I thought I would ask.

Thanks

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Jun 2010, 09:01 AM
Hi Greek1,

Can you post more info (XAML) how exactly the grid is bound to this DomainDataSource?

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Greek1
Top achievements
Rank 1
answered on 17 Jun 2010, 09:06 AM
 <riaControls:DomainDataSource Name="CandidateDataSource" 
                                      QueryName="GetCandidatesQuery" 
                                      AutoLoad="True" FilterOperator="And">  
                <riaControls:DomainDataSource.DomainContext> 
                    <web:NeuHireContext/> 
                </riaControls:DomainDataSource.DomainContext> 
                <riaControls:DomainDataSource.FilterDescriptors>                   
                </riaControls:DomainDataSource.FilterDescriptors> 
            </riaControls:DomainDataSource> 
 
            <TGridView:RadGridView x:Name="rgvCandidates" telerik:StyleManager.Theme="Office_Blue"   
                                   ItemsSource="{Binding ElementName=CandidateDataSource, Path=Data}"      
                                   AutoGenerateColumns="False" Background="{x:Null}" Grid.Row="1" Margin="10" RowStyle="{StaticResource GridViewRowStyle1}"   
                                   Foreground="{StaticResource DeepBlueTextBrush}" CanUserDeleteRows="False" CanUserInsertRows="False" EditTriggers="None"   
                                   DataLoadMode="Asynchronous" RowIndicatorVisibility="Visible" >                 
                <TGridView:RadGridView.Columns> 
                    <TGridView:GridViewDataColumn Header="First Name" DataMemberBinding="{Binding FirstName}" /> 
                    <TGridView:GridViewDataColumn Header="Last Name" DataMemberBinding="{Binding LastName}" /> 
                    <TGridView:GridViewDataColumn Header="Region" DataMemberBinding="{Binding Region.RegionName}" /> 
                    <TGridView:GridViewDataColumn Header="Practice" DataMemberBinding="{Binding Practice.PracticeName}" /> 
                    <TGridView:GridViewDataColumn Header="Stage" DataMemberBinding="{Binding RecruitmentStage.Display}" /> 
                    <TGridView:GridViewDataColumn Header="Status" DataMemberBinding="{Binding CandidateStatus.Display}" /> 
                    <TGridView:GridViewDataColumn Header="Recruiter"  DataMemberBinding="{Binding Recruiter.Login}" UniqueName="Recruiter"/>                                              
                </TGridView:RadGridView.Columns> 
            </TGridView:RadGridView> 

Here you go
0
Veselin Vasilev
Telerik team
answered on 17 Jun 2010, 01:02 PM
Hi,

One of the possible solutions is this:
Add the column filter descriptor in the LoadedData event of the domain datasource. This approach has the following pros and cons:
Pros: the filter funnel of the grid is updated accordingly. Clicking on the Clear filter will clear the filter and show all the data automatically.
Cons: initially all the data is loaded by the select query and then it is filtered. If you have a lot of data this would affect the initial loading of the page.

This was the easier option.


The other one is to work directly with the filter descriptors of the DomainDataSource.
Here is what you can do in this case:

1. Create filter descriptor of the DomainDataSource

System.Windows.Controls.FilterDescriptor filter = new System.Windows.Controls.FilterDescriptor()
{
    Operator = System.Windows.Controls.FilterOperator.Contains,
    PropertyPath = "Recruiter",
    Value = "Kev"
};
 
CandidateDataSource.FilterDescriptors.Add(filter);

This way only the filtered data will come to the client.

2. To update the filtering funnel of the gridview - you can add the custom filter descriptor to the gridview in the LoadedData event of the domain datasource (as in the first approach).

The problem with this approach is clearing the filter - it will clear the filter of the visible data (which is already filtered) because the domain datasource will still have its filter descriptor in place. You can subscribe to the Filtering event of the grid and manipulate the filter descriptors of the domain datasource as shown in our online demo.
Alternatively, you can have a separate Clear button on the page which will remove the filter descriptors of the domain datasource.

In addition, you can check this blog post:
Pure Server-Side Filtering with RadGridView and WCF RIA Services



Best wishes,
Veskoni
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Greek1
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Greek1
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or