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

Server-side filtering with GridView + DataPager + IPagedCollectionView

7 Answers 371 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fabrice
Top achievements
Rank 1
Fabrice asked on 24 Aug 2015, 03:07 PM

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

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 27 Aug 2015, 10:43 AM
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
0
Fabrice
Top achievements
Rank 1
answered on 27 Aug 2015, 11:31 AM

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.

 

0
Fabrice
Top achievements
Rank 1
answered on 27 Aug 2015, 01:58 PM
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!
0
Fabrice
Top achievements
Rank 1
answered on 28 Aug 2015, 10:50 AM

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.

 

0
Dimitrina
Telerik team
answered on 28 Aug 2015, 10:55 AM
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
0
Datafyer
Top achievements
Rank 1
answered on 06 Apr 2016, 10:51 PM

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.

0
Fabrice
Top achievements
Rank 1
answered on 07 Apr 2016, 08:16 AM

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

Tags
GridView
Asked by
Fabrice
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Fabrice
Top achievements
Rank 1
Datafyer
Top achievements
Rank 1
Share this question
or