Server-side filtering with GridView + DataPager + IPagedCollectionView

8 posts, 1 answers
  1. Fabrice
    Fabrice avatar
    22 posts
    Member since:
    Jan 2015

    Posted 24 Aug 2015 Link to this post

    I'm implementing a paged datasource successfully using a GridView + DataPager consuming a IPagedCollectionView, which is filled every time a page is requested with data from a REST-ish API. But I'm having trouble implementing filtering using the GridView's filter row, as it seems the default behavior of the GridView is to filter the data of the current page. I wanted to be able to just send the filters to the API, do the filtering + paging there, and return the data already filtered. In a nutshell I'm trying to use wpf's GridView like asp.net mvc's Grid (http://demos.telerik.com/aspnet-mvc/grid/index) which sends queries to the server via AJAX with the filters and sorts.

     

    I already tried to implement ICollectionView, but the GridView still does what it normally does.

     

    Handling the Filtering event of the GridView doesn't look like the right way to go, I either set e.Handled = true and get the same behavior, or set e.Cancel = true and refresh the data and the filtering information is cleaned. Can someone point me to the right direction / resources?

  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 27 Aug 2015 Link to this post

    Hi,

    Filtering in RadGridView is a data operation and the data engine internally generates and executes a LINQ query appending a Where clause to the source collection. If the source is IQueryable, then the query is to be executed on the server. This logic cannot be changed on Filtering event since it is based on the bound source collection. You can also refer to the documentation on Filtering where the principals are explained in details. 

    As to RadDataPager, every time when navigating to a page, RadDataPager internally builds a LINQ query appending Skip and Take clauses and then this query is to be executed on the server. When binding the pager to a LINQ-enabled data source (i.e. IQueryable), the paging will happen on the server out-of-the-box. In case the pager is bound to an IQueryable, it will automatically append Skip(n) and Take(m) statements to this query.

    You can find RadDataPager WPF Demos where filtering is on all items. 

    Regards,
    Dimitrina
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Fabrice
    Fabrice avatar
    22 posts
    Member since:
    Jan 2015

    Posted 27 Aug 2015 in reply to Dimitrina Link to this post

    I have an half working solution - using IQueryable, good to know I'm on the right track - , but now I'm having the issue of having the situation:

     

    1) I set a random filter on a random column

    2) the GridView calls Count() on the original, unfiltered IQueryable

    3) CreateQuery is called in the Provider with the Where expression and populate the GridView with the result of it, while leaving the Pager still reporting the number of pages implicit by the earlier Count() call.

     

    Maybe the IPagedCollectionView is getting in the way? I'll try to play a bit more and get back to you.

     

  5. Fabrice
    Fabrice avatar
    22 posts
    Member since:
    Jan 2015

    Posted 27 Aug 2015 in reply to Fabrice Link to this post

    I took off IPagedCollectionView and fixed the binding of the Pager based on the demo, and I'm already getting the Take() in my provider. I'm almost there!
  6. Fabrice
    Fabrice avatar
    22 posts
    Member since:
    Jan 2015

    Posted 28 Aug 2015 in reply to Fabrice Link to this post

    Finally got it to work! Took longer than anticipated due to the fact that I had a lot of code from earlier experiments that was actually hampering what was well done.

    For future reference, my DataSource class drops the ICollectionView and IPagedCollectionView interfaces from earlier experiments, and now implements IQueryableCollectionView, IQueryable, IOrderedQueryable and IEnumerable (among typed versions of these interfaces and the necessary INotify*Changed apparatus), and has its own IQueryProvider.

     

  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Aug 2015 Link to this post

    Hi,

    I am glad to hear that. Thank you for sharing the outcome with the community.

    Regards,
    Dimitrina
    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
  8. Patrick
    Patrick avatar
    55 posts
    Member since:
    Jun 2008

    Posted 06 Apr in reply to Fabrice Link to this post

    Fabrice, I know it has been a while however is it possible to share more code or a working sample?

    I am trying to do the same thing and it seems like it can get very tricky.
    Thanks.

  9. Fabrice
    Fabrice avatar
    22 posts
    Member since:
    Jan 2015

    Posted 07 Apr in reply to Patrick Link to this post

    Patrick, sorry but I'm not at liberty to share the code. I implemented a Linq Provider that only fetches data from the server when actually executing the linq query (it's still not at 100% though, probably needs rewriting now that i'm more knowledgeable on the subject), these are good starting points:

    https://msdn.microsoft.com/en-us/library/bb546158(v=vs.110).aspx

    http://weblogs.asp.net/mehfuzh/writing-custom-linq-provider

    And I highly recommend this series:

    https://blogs.msdn.microsoft.com/mattwar/2008/11/18/linq-building-an-iqueryable-provider-series/

    There's also this project https://iqtoolkit.codeplex.com/ although I can't really say what you can with it

Back to Top
UI for WPF is Visual Studio 2017 Ready