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?
7 Answers, 1 is accepted
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.
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.
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.
I am glad to hear that. Thank you for sharing the outcome with the community.
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.
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:
And I highly recommend this series:
There's also this project https://iqtoolkit.codeplex.com/ although I can't really say what you can with it