This is a migrated thread and some comments may be shown as answers.
RadGridView Filtering and DataPager
9 Answers 356 Views
This is a migrated thread and some comments may be shown as answers.
D1d13r
Top achievements
Rank 1
D1d13r asked on 10 Oct 2009, 01:51 AM
Hello,

I am testing the RadGridView Ria Services demo using my own DomainDataSource and am encountering a different result than the one in your demo when using the filters.

When I filter the data using any column it will filter the data of the current page I am on instead of reloading the entire dataset. Would you know what could be causing this?

Basically I have 118 pages of data before filtering and 118 pages of data after filtering but the filter is applied on a page basis. The data doesn't reload like it does on your demo.

Here is my code:

    <Grid x:Name="LayoutRoot">  
        <Grid.RowDefinitions> 
            <RowDefinition /> 
            <RowDefinition Height="30" /> 
        </Grid.RowDefinitions> 
        <riaControls:DomainDataSource LoadingData="DomainDataSource1_LoadingData" LoadedData="DomainDataSource1_LoadedData" x:Name="lookupListDataSource" QueryName="GetLookupsQuery" AutoLoad="True">  
            <riaControls:DomainDataSource.DomainContext> 
                <ds:Context/> 
            </riaControls:DomainDataSource.DomainContext> 
            <riaControls:DomainDataSource.FilterDescriptors> 
                <riaData:FilterDescriptorCollection LogicalOperator="Or" /> 
            </riaControls:DomainDataSource.FilterDescriptors> 
        </riaControls:DomainDataSource> 
        <controls:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" Width="520" Height="Auto" MinHeight="100"  ItemsSource="{Binding Data, ElementName=lookupListDataSource}">  
            <controls:RadGridView.Columns> 
                <controls:GridViewDataColumn UniqueName="Description" Header="Description" /> 
                <controls:GridViewDataColumn UniqueName="Type" Header="Type" /> 
            </controls:RadGridView.Columns> 
        </controls:RadGridView> 
        <data:DataPager Grid.Row="1" Width="520" PageSize="8" Source="{Binding Data, ElementName=lookupListDataSource}"></data:DataPager> 
    </Grid> 
    public partial class ExcelExport : Page  
    {  
        public ExcelExport()  
        {  
            InitializeComponent();  
        }  
 
        private void DomainDataSource1_LoadingData(object sender, System.Windows.Controls.LoadingDataEventArgs e)  
        {  
            RadGridView1.IsBusy = true;  
        }  
 
        private void DomainDataSource1_LoadedData(object sender, System.Windows.Controls.LoadedDataEventArgs e)  
        {  
            RadGridView1.IsBusy = false;  
        }  
 
        private void AddDomainDataSourceFilterDescriptor(Telerik.Windows.Data.FilterDescriptor descriptor)  
        {  
            System.Windows.Data.FilterDescriptor fd = new System.Windows.Data.FilterDescriptor();  
            fd.PropertyPath = descriptor.Member;  
            fd.Value = new System.Windows.Data.Parameter() { Value = descriptor.Value };  
            fd.Operator = (System.Windows.Data.FilterOperator)Enum.Parse(typeof(System.Windows.Data.FilterOperator), descriptor.Operator.ToString(), true);  
            lookupListDataSource.FilterDescriptors.Add(fd);  
        }  
 
        private void RemoveDomainDataSourceFilterDescriptor(Telerik.Windows.Data.FilterDescriptor descriptor)  
        {  
            System.Windows.Data.FilterDescriptor fd =  
                     (from d in lookupListDataSource.FilterDescriptors  
                      where d.PropertyPath == descriptor.Member &&  
                            d.Operator == (System.Windows.Data.FilterOperator)Enum.Parse(typeof(System.Windows.Data.FilterOperator), descriptor.Operator.ToString(), true) &&  
                            d.Value.Value == descriptor.Value  
                      select d).FirstOrDefault();  
 
            if (fd != null)  
            {  
                lookupListDataSource.FilterDescriptors.Remove(fd);  
            }  
        }  
 
        private void RadGridView1_Filtering(object sender, Telerik.Windows.Controls.GridView.GridViewFilteringEventArgs e)  
        {  
            using (lookupListDataSource.DeferLoad())  
            {  
                foreach (Telerik.Windows.Data.FilterDescriptor d in e.RemovedDescriptors)  
                {  
                    RemoveDomainDataSourceFilterDescriptor(d);  
                }  
 
                foreach (Telerik.Windows.Data.FilterDescriptor d in e.AddedDescriptors)  
                {  
                    AddDomainDataSourceFilterDescriptor(d);  
                }  
            }  
        }  
 
 
        // Executes when the user navigates to this page.  
        protected override void OnNavigatedTo(NavigationEventArgs e)  
        {  
        }  
    } 

Thank you in advance for your help.

Didier

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Oct 2009, 05:57 AM
Hello Didier,

Indeed distinct values are populated from the current page however the grid filtering will be applied for the entire collection - please check the code of Filtering event handler.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
D1d13r
Top achievements
Rank 1
answered on 12 Oct 2009, 07:50 PM
Hello Vlad,

Thanks for your answer.

The code is exactly the same as the one from your demo. The only difference is that I am pulling the data from the domaindatasource.

        private void AddDomainDataSourceFilterDescriptor(Telerik.Windows.Data.FilterDescriptor descriptor)   
        {   
            System.Windows.Data.FilterDescriptor fd = new System.Windows.Data.FilterDescriptor();   
            fd.PropertyPath = descriptor.Member;   
            fd.Value = new System.Windows.Data.Parameter() { Value = descriptor.Value };   
            fd.Operator = (System.Windows.Data.FilterOperator)Enum.Parse(typeof(System.Windows.Data.FilterOperator), descriptor.Operator.ToString(), true);   
            lookupListDataSource.FilterDescriptors.Add(fd);   
        }   
  
        private void RemoveDomainDataSourceFilterDescriptor(Telerik.Windows.Data.FilterDescriptor descriptor)   
        {   
            System.Windows.Data.FilterDescriptor fd =   
                     (from d in lookupListDataSource.FilterDescriptors   
                      where d.PropertyPath == descriptor.Member &&   
                            d.Operator == (System.Windows.Data.FilterOperator)Enum.Parse(typeof(System.Windows.Data.FilterOperator), descriptor.Operator.ToString(), true) &&   
                            d.Value.Value == descriptor.Value   
                      select d).FirstOrDefault();   
  
            if (fd != null)   
            {   
                lookupListDataSource.FilterDescriptors.Remove(fd);   
            }   
        }   
  
        private void RadGridView1_Filtering(object sender, Telerik.Windows.Controls.GridView.GridViewFilteringEventArgs e)   
        {   
            using (lookupListDataSource.DeferLoad())   
            {   
                foreach (Telerik.Windows.Data.FilterDescriptor d in e.RemovedDescriptors)   
                {   
                    RemoveDomainDataSourceFilterDescriptor(d);   
                }   
  
                foreach (Telerik.Windows.Data.FilterDescriptor d in e.AddedDescriptors)   
                {   
                    AddDomainDataSourceFilterDescriptor(d);   
                }   
            }   
        }   
  


Didier
0
Vlad
Telerik team
answered on 13 Oct 2009, 05:51 AM
Hi Didier,

You can easily debug the service using Firebug to check if the filtering is applied server-side. I've attached screenshot from our online demo with DomainDataSource.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Wayne Bradney
Top achievements
Rank 1
answered on 14 May 2010, 02:30 AM
It's not clear to me what's supposed to happen here. I seem to be getting the same problem as above -- I have a RadDataGrid bound to a DomainDataSource with 135 items and LoadSize=20. The RadGridView has a page size of 10. The RadGridView and a RadDataPager are together in a stack panel.

When no filter is applied I get 14 pages, and I see 10 items on Page 1. So far so good. When I apply a certain filter in the RadGridView, I now see 5 items on Page 1, and the RadDataPager still tells me there are 14 pages. As I page through, it's clear that the filter is being applied page-by-page -- some pages have 1 or two items, some pages show no items at all, but there are still 14 pages.

I've compared my code to the Paging sample and it seems to be the same -- it's simply not working that way for me. Is there some other setting I need to be aware of?
0
Rossen Hristov
Telerik team
answered on 14 May 2010, 08:54 AM
Hi Wayne Bradney,

The behavior you are describing is quite normal. When you filter RadGridView, you are filtering on the client. In other words, you are filtering the current view (current page) and not the entire data set on the server. That is why the pages coming from the server remain constant. You are simply hiding some of the client records on the current page. It seems that you want to filter on the server.

If you want to filter on the server you have two options.

Translate RadGridView's FilterDescriptors to DomainDataSource filters in the filtering event handler. This technique is demonstrated in this online example.

The better approach would be to replace the default filtering control with a custom one that filters solely on the server. No client-side filtering whatsoever.

This approach can be seen in this online example. My blog post explains how to develop this pure server-side filtering control. This is a must read if want to understand how things work. Once you start filtering the DomainDataSource (server) then your page count will start changing like you want.

Also, I think that my extensive blog about paging might be interesting for you.

Let us know if there are problems.

Sincerely yours,
Ross
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
Mariusz
Top achievements
Rank 1
answered on 05 Aug 2011, 12:52 PM
Hello,

I'm having similar problem to the one described by Wayne with the difference that if i filter by one column it works fine. When i add filtering by another column number of pages rises and number of visible results decreases. I chcecked that some filtering is being done on client side. What i see is that correct, filtered, results are spread across too many pages.This only happens when i filter by more than one column.

My code is almost the same as in this example: http://demos.telerik.com/silverlight/#GridView/DomainDataSource, but even if made a mistake in my modifications could you explain to me how does the server-side know how to connect different filters from different columns? DomainDataSource connects them all using "Or" operator whereas only RadGridView knows real structure of the filter and filters data that came form the server. Example code doesn't seem to do anything in that matter and somehow example works fine and my code doesn't. I don't know what i'm missing.

I'm using RadControls for Silverlight Q1 2011 SP1.

Regards,
Rafal 
0
Rossen Hristov
Telerik team
answered on 05 Aug 2011, 01:34 PM
Hi Rafal,

You no longer need to do this in the old complex way.

Have you seen our RadDomainDataSource control? Here is more information:

Due to the unplanned for increase in interest in development of Silverlight line of business applications, we are making our latest addition to our Silverlight suite available before our next major release so we can enable our clients to focus on delivering their great applications without worrying about any “plumbing”. Our new Domain Data Source components ensure seamless integration between Telerik data source controls and WCF RIA Services. Now all the powerful data-shaping features of Telerik RadControls can directly translate to your domain service – filtering and sorting operations, for example, are performed directly on the server with minimum development effort. Our Domain Data Services support includes both a component that you can embed in your Silverlight page and a CollectionView Implementation that you can use in your view models for a truly MVVM-enabled scenario. 
To explore the new RadDomainDataSource control in greater depth, please check its online examples and take a look at the following blog posts:

I hope this helps. Best wishes,
Ross
the Telerik team

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

0
Leonard
Top achievements
Rank 1
answered on 31 Aug 2015, 02:38 PM

Hi Rossen Hristov, when you say 

"The behavior you are describing is quite normal. When you filter RadGridView, you are filtering on the client. In other words, you are filtering the current view (current page) and not the entire data set on the server. That is why the pages coming from the server remain constant. You are simply hiding some of the client records on the current page. It seems that you want to filter on the server. "

When the collection is ObservableCollection it's working fine. can you explain me please?

Thanks.

0
Petya
Telerik team
answered on 03 Sep 2015, 01:14 PM
Hello Leonard,

Please take a look at my answer in the other thread you posted here.

Regards,
Petya
Telerik
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 Feedback Portal and vote to affect the priority of the items
Asked by
D1d13r
Top achievements
Rank 1
Answers by
Vlad
Telerik team
D1d13r
Top achievements
Rank 1
Wayne Bradney
Top achievements
Rank 1
Rossen Hristov
Telerik team
Mariusz
Top achievements
Rank 1
Leonard
Top achievements
Rank 1
Petya
Telerik team
Share this question
or