RadGrid's client-side databinding capabilities got boosted to a new level with the Q3 2010 release of Telerik RadControls for ASP.NET AJAX. RadGrid now supports automatic databinding to OData web services. For those of you who have never heard, OData (short for Open Data) is a data exchange protocol that enables data transactions to be carried over standard web protocols (HTTP, Atom, and JSON). OData exposes your data over the web to a variety of consumers, building on technology that is widely adopted.

With the Q3 2010 release, we have added automatic client-side databinding support for OData services. To configure RadGrid for binding to an OData service, you need to set 3 properties:

  • RadGrid.ClientSettings.DataBinding.Location - specifies the root URI for an OData service
  • RadGrid.ClientSettings.DataBinding.DataService.TableName - specifies the table name or the name of a Data Collection in an OData service.
  • RadGrid.ClientSettings.DataBinding.DataService.Type - specifies the service type RadGrid is databinding to. Supported service types are ADO.NET Data Service* and OData service. Default is GridClientDataServiceType.ADONet, you need to set it to GridClientDataServiceType.OData.

Here is how a sample RadGrid setup may look in the page markup:

RadGrid setup for OData binding at same domain

Running this page you would get RadGrid automatically make a JSON request to the following URL:

http://[root web application URL]/Northwind.svc/Products?&$inlinecount=allpages&

This URL conforms to the OData URI format specification. You can see start row index and maximum row count is requested with the $skip and $top URL parameters, providing for automatic data paging. In the same way, sorting and filtering is supported through the $orderby and $filter query options. Bottom line, if you have an OData service to consume, you get automatic binding, paging, filtering and sorting of the data with RadGrid. At the cost of setting a couple of properties.

But there is more to the story. What about OData services exposed at remote URLs? JSON, or any other http request initiated from javascript is restricted by the same origin policy. In Q3 2010, we have added JSONP support to RadGrid. Using JSONP, you can make remote calls to services that support the JSONP data response format. OData supports JSONP through the $callback URL parameter. Setting this parameter to the name of a callback function will have your JSON data wrapped in a call to this function. In RadGrid, you specify JSONP data exchange format through the RadGrid.ClientSetttings.DataBinding.ResponseType property. Translating the above RadGrid definition to use a remote OData service, we get:

RadGrid setup for OData binding at a remote domain

In the above RadGrid setup, I have the full URL of my OData service, and it is hosted at a remote domain. In fact, this is a sample OData service exposing the Northwind database - one of the sample OData services hosted at odata.org. I have also specified the response type to JSONP. Now RadGrid knows it needs to make JSONP requests to the remote URL. I can consume a remote OData service with RadGrid!

Want to give it a try yourself? Download the sample project.

* ADO.NET Data Services in this blog post refers to the technology formerly known as Atoria Services that has moved as a first-class component in .NET Framework 3.5 SP1. This is slightly different from and a predecessor to what is today WCF Data Services. In .NET Framework 4.0, Microsoft has moved this technology toward full compliance with the OData protocol. RadGrid supports both variants and you can see a live demo of RadGrid binding to ADO.NET Data Services. This is different from binding to OData services discussed in this topic. To differentiate between the two, the service type is explicitly specified by the developer using the RadGrid.ClientSettings.DataBinding.DataService.Type property.

About the Author

Iana Tsolova

is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.

Related Posts


Comments are disabled in preview mode.