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

Binding to the Web API via RadClientDatasource

2 Answers 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Denis
Top achievements
Rank 1
Denis asked on 20 Jun 2014, 05:46 PM
Hello.
Is RadClientDatasource supports OData with Web API?
I have one Web API controller derived from ApiController and another controller derived from ODataController. Both controller able to return data, I can see it in a browser.
I'm trying to bind a grid to each service using RadClientDatasource. 
The grid which bound to regular Web API displays data with no problems.
But the grid bound to the OData service always empty. I have tried to use all DataTypes with OData - XML, JSON, JSONP - with no results.

The markup:
01.<t:RadClientDataSource runat="server" ID="cdsWA">
02.    <DataSource>
03.        <WebServiceDataSourceSettings ServiceType="Default">
04.            <Select Url="http://localhost:52339/api/Tests" DataType="JSON" />
05.        </WebServiceDataSourceSettings>
06.    </DataSource>
07.    <Schema>
08.        <Model>
09.            <t:ClientDataSourceModelField FieldName="Id" DataType="Number" />
10.            <t:ClientDataSourceModelField FieldName="Text" DataType="String" />
11.            <t:ClientDataSourceModelField FieldName="Number" DataType="Number" />
12.        </Model>
13.    </Schema>
14.</t:RadClientDataSource>
15. 
16.<t:RadClientDataSource runat="server" ID="cdsOD">
17.    <DataSource>
18.        <WebServiceDataSourceSettings ServiceType="OData">
19.            <Select Url="http://localhost:52339/odata/OTests" DataType="JSONP" />
20.        </WebServiceDataSourceSettings>
21.    </DataSource>
22.    <Schema>
23.        <Model>
24.            <t:ClientDataSourceModelField FieldName="Id" DataType="Number" />
25.            <t:ClientDataSourceModelField FieldName="Text" DataType="String" />
26.            <t:ClientDataSourceModelField FieldName="Number" DataType="Number" />
27.        </Model>
28.    </Schema>
29.</t:RadClientDataSource>
30. 
31.<div>GRID</div>
32.<t:RadGrid runat="server" ID="rgWebapi" ClientDataSourceID="cdsWA">
33.    <MasterTableView>
34.        <Columns>
35.            <t:GridBoundColumn DataField="Id" HeaderText="ID"></t:GridBoundColumn>
36.            <t:GridBoundColumn DataField="Text" HeaderText="TEXT"></t:GridBoundColumn>
37.            <t:GridBoundColumn DataField="Number" HeaderText="NUMBER"></t:GridBoundColumn>
38.        </Columns>
39.    </MasterTableView>
40.</t:RadGrid>
41. 
42.<t:RadGrid runat="server" ID="rgOData" ClientDataSourceID="cdsOD">
43.    <MasterTableView>
44.        <Columns>
45.            <t:GridBoundColumn DataField="Id" HeaderText="ID"></t:GridBoundColumn>
46.            <t:GridBoundColumn DataField="Text" HeaderText="TEXT"></t:GridBoundColumn>
47.            <t:GridBoundColumn DataField="Number" HeaderText="NUMBER"></t:GridBoundColumn>
48.        </Columns>
49.    </MasterTableView>
50.</t:RadGrid>


Thank you,
Denis Mitropolskiy

2 Answers, 1 is accepted

Sort by
0
Denis
Top achievements
Rank 1
answered on 20 Jun 2014, 05:54 PM
In addition OData service call results:
{
  "odata.metadata":"http://localhost:52339/odata/$metadata#OTests","value":[
    {
      "Id":1,"Text":"TEXT1","Number":0
    },{
      "Id":2,"Text":"TEXT2","Number":0
    },{
      "Id":3,"Text":"TEXT3","Number":0
    },{
      "Id":4,"Text":"TEXT4","Number":0
    }
  ]
}
0
Marin
Telerik team
answered on 25 Jun 2014, 08:19 AM
Hi,

In the case of the binding to OData service I see that the array with data comes in a variable called value:
{
  "odata.metadata":"http://localhost:52339/odata/$metadata#OTests","value":[
    {
      "Id":1,"Text":"TEXT1","Number":0
    },{
      "Id":2,"Text":"TEXT2","Number":0
    },{
      "Id":3,"Text":"TEXT3","Number":0
    },{
      "Id":4,"Text":"TEXT4","Number":0
    }
  ]
}

You should also specify the name of the field that contains the records in the setting of the ClientDataSource like this:

<telerik:RadClientDataSource runat="server" ID="cdsOD">
            <DataSource>
                <WebServiceDataSourceSettings ServiceType="OData">
                    <Select Url="http://localhost:52339/odata/OTests" DataType="JSONP" />
                </WebServiceDataSourceSettings>
            </DataSource>
            <Schema DataName="value">
                <Model>
                    <telerik:ClientDataSourceModelField FieldName="Id" DataType="Number" />
                    <telerik:ClientDataSourceModelField FieldName="Text" DataType="String" />
                    <telerik:ClientDataSourceModelField FieldName="Number" DataType="Number" />
                </Model>
            </Schema>
        </telerik:RadClientDataSource>

Additionally if the problem persists you can check the network tab in the browser developer tools to see if the there's any successful request to the web service or if the server returned any errors.

I hope this helps. 

Kind Regards,
Marin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Denis
Top achievements
Rank 1
Answers by
Denis
Top achievements
Rank 1
Marin
Telerik team
Share this question
or