RadGridView Filtering and DataPager

10 posts, 0 answers
  1. D1d13r
    D1d13r avatar
    2 posts
    Member since:
    Jul 2012

    Posted 09 Oct 2009 Link to this post

    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
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Oct 2009 Link to this post

    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.
  3. DevCraft banner
  4. D1d13r
    D1d13r avatar
    2 posts
    Member since:
    Jul 2012

    Posted 12 Oct 2009 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 13 Oct 2009 Link to this post

    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.
  6. Wayne Bradney
    Wayne Bradney avatar
    12 posts
    Member since:
    Apr 2010

    Posted 13 May 2010 Link to this post

    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?
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 14 May 2010 Link to this post

    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.
  8. Mariusz
    Mariusz avatar
    24 posts
    Member since:
    Mar 2011

    Posted 05 Aug 2011 Link to this post

    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 
  9. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 05 Aug 2011 Link to this post

    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 >>

  10. Leonard
    Leonard avatar
    22 posts
    Member since:
    Jan 2013

    Posted 31 Aug 2015 in reply to Rossen Hristov Link to this post

    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.

  11. Petya
    Admin
    Petya avatar
    975 posts

    Posted 03 Sep 2015 Link to this post

    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
Back to Top
DevCraft banner