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

Use Filterquery from GridView serverside

10 Answers 172 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 18 Feb 2011, 11:13 AM
Hi

In our Silverlight 4 application we use RIA services and the telerik Gridview control in combination with the domaindatasource and the DataPager.  The user can enter filtercriterias on the grid. Furhtermore the list is paged.

We would now like to generate an excelfile depending on the filter criterias defined by the user. The workflow is the following:
1. User enters filter criterias on the grid. The user will then see a paged view of the items.
2. User pushes button to create excel report of all the data that corresponds to the entered filter criteria. 
3. Serverside-> The server recieves the query with all the criterias, gets the data from the database and creates the excel file and eventually sends it back to the user.

How can i achieve this using the Gridview control in combination with the domainDatasource (on which we set the page size)?
I somehow need to get the query defined client side, ensure that there is no paging and send it back to the server. We use RIA-Services and the entity framework. 

It would be great if this works. 

Thanks for any help.

Dan





 


10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 18 Feb 2011, 12:23 PM
Hello,

 For server-side filtering with standard DomainDataSource you can check this demo. In our RadDomainDataSource this is completely codeless. 

All the best,
Vlad
the Telerik team
0
Dan
Top achievements
Rank 1
answered on 18 Feb 2011, 02:01 PM
Hi

Wow, you are quick. Thanks for your answer. I am not sure if you understood what i actually meant, but i guess I can defer what I need from the referenced demo. I will have register events of the gridview control, defer the loading in the domain datasource, add the filterdescriptors in the code behind, and eventually trigger loading the items. 
Thanks and greetings 
0
Dan
Top achievements
Rank 1
answered on 08 Apr 2011, 01:56 PM
Hi

I just checked the example but I do not get how this shows how i can send all to filter criteria to the server. (i believe the link used to point to a different example, maybe it still exists under a different url)

My requirements are:

1. Client: Collect the filtercriteria from the paged grid (entered by the user)
2. Server: Recieve the filter criteria (but ensure that there is no paging)
3. Server: Get all rows matching the filter criteria ... (and create an excel file but this is not part of the question)

How can i do this?

Greetings and thanks in advance

Dan
0
Rossen Hristov
Telerik team
answered on 08 Apr 2011, 02:18 PM
Hello Dan,

You can do everything with

1. Bind RadGridView to RadDomainDataSource. Set RadDomainDataSource to AutoLoad=false.
2. If your user filters RadGridView on the client through the UI, under the hood it will transfer all of this filtering criteria to RadDomainDataSource.
3. Once you call RadDomainDataSource.Load you will perform filtering on the server and bring data back to the client which will be displayed in RadGridView.
4. If RadDomainDataSource.AutoLoad were set to true, this would happen automatically every time the user filters on the client without the need to do absolutely anything additional.

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 itsonline examples and take a look at the following blog posts:

Every blog post has a sample project attached. I am sure that you will find them very interesting.

The examples are also very interesting.

I hope this helps.

Greetings,
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
Dan
Top achievements
Rank 1
answered on 08 Apr 2011, 03:32 PM
Hi

Tanks for your quick answer. The links are interesting but unfortunately not exactly what i am looking for (by the way, some sample projects dont work with the latest silverlight controls)

The GridView in combination with the DomainDataSource and Ria services (and the datapager) works fine. Sorting, Filtering, Paging, everthing works the way I want it. Unfortunately, I my requirements are a little different:
1. Client side: User clicks a button
2. Client side: The filter criterias are collected (but without paging!!!) 
3. Client side: The query is sent to  the server  (this must happen in C# code, and i cannot just call the load method-> the grid itself should not be affected or reloaded!)
4. Server side: The query is executed and a specific excel file containing the retrieved data, is created
5. Client side: The created file is downloaded
My problem is with stepp 2, 3 and 4. I need to send the query to the server (without paging) where, depending on the filter criteria, a file is created. The actual data is not (!) sent back to the client.

Unfotunately, the domain datasource does not have a property where i can access the query and then manually send to the server. 
How can i achieve the desired result?
0
Rossen Hristov
Telerik team
answered on 08 Apr 2011, 04:24 PM
Hello Dan,

All of the currently applied filters of RadGridView are found in its FilterDescriptors collection.

You might delete the RadDomainDataSource and work directly with your DomainContext. You will have to read what FilterDescriptors RadGridView has and transfer this information to the EntityQuery of interest. This can be done by using one of our extension methods called Where:

public static EntityQuery<TEntity> Where<TEntity>(this EntityQuery<TEntity> source, FilterDescriptorCollection filterDescriptors)
    where TEntity : Entity
{
    return EntityQueryPlaceholder<TEntity>.BuildEntityQuery(source, new EntityQueryPlaceholder<TEntity>().Where(filterDescriptors).Expression);
}

This extension method is found in the Telerik.Windows.Controls.DomainServices assembly, in the static class called EntityQueryExtensions.

What this method does is basically, you supply a "raw" EntityQuery, for example this.yourDomainContext.GetEmployeesQuery() and a collection of FilterDescriptors, for example the RadGridView.FilterDescriptors. It will return a new EntityQuery with all the filtering information attached.

You can then load this new "filtered" EntityQuery with your DomainContext and from then on you are on your own. You can do anything on the server and the client, but that goes out of Telerik's scope and enters the WCF RIA Services domain. Same applies for the server-side generation of the excel file and its transport to the client.

I hope this helps.


Regards,
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
Justin Wilson
Top achievements
Rank 1
answered on 18 Apr 2011, 02:38 PM
Do you have an example of how to use the EntityQueryExtensions?

Thanks,
Justin
0
Rossen Hristov
Telerik team
answered on 18 Apr 2011, 03:59 PM
Hello Justin Wilson,

We don't have an example. It's pretty straightforward -- just two extension methods working on an EntityQuery.

I have explained everything in my previous post. 

Let me know if you have any specific questions.

Regards,
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
Justin Wilson
Top achievements
Rank 1
answered on 18 Apr 2011, 04:29 PM
I have a very similar situation as Dan.  I have users filtering the RadGridView on the client side.  I need to create an export on the server side with the exact same data in the Grid.  Currently, I am passing the paramaters to pull the data from the database, repulling the data, and creating the export.  I need a way to apply the filters set in the RadGridView to the data on the server side. 

I am not clear as to what to pass into the EntityQueryExtensions Where method.  Are you are using this extension to create an entityquery object and passing this back through the WCF an applying this to the raw data?  Any help would be appreciated.  I may be way off on how to use this.

EntityQuery<MemberReportItem> test = Telerik.Windows.Controls.DomainServices.EntityQueryExtensions.Where("Not Clear what to Pass In", this.DataGridControl.FilterDescriptors);

Thanks,
Justin
0
Rossen Hristov
Telerik team
answered on 18 Apr 2011, 04:43 PM
Hello Justin Wilson,

You will answer your own question if you learn about .NET Extension Methods. Please, read this before going on. 

Now, you have two input things:

1. Some FilterDescriptors coming from RadGridView
2. A non-filtered EntityQuery<T> obtained from the DomainContext, i.e. this.domainContext.GetEmployeesQuery(); This is the "this" which you are "Not Clear what to Pass In"

What you need to produce is another EntityQuery<T>, but this time with some filtering information embedded. You will then send this new filtered EntityQuery to the server by using your DomainContext.

So you simply do this:

var myFilteredQuery = this.myOriginalQuery.Where(this.RadGridView.FilterDescriptors);

That's it. You then send this new filtered query to the server and you will get the filtered data back.

Kind regards,
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
Tags
GridView
Asked by
Dan
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Dan
Top achievements
Rank 1
Rossen Hristov
Telerik team
Justin Wilson
Top achievements
Rank 1
Share this question
or