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

[Solved] Client side binding and nested JSON objects

4 Answers 335 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Haroon
Top achievements
Rank 1
Haroon asked on 31 Aug 2009, 07:08 AM
Hi,

I'm trying to bind a radgrid from client side with a ASMX web service using this markup:

<telerik:RadGrid ID="RadGrid1" AllowSorting="true" AllowPaging="true" AllowFilteringByColumn="true" 
            AutoGenerateColumns="false" runat="server"
            <MasterTableView> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="Id" HeaderText="Id" DataType="System.Guid" Visible="false" /> 
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Title" /> 
                    <telerik:GridBoundColumn DataField="Cause.Name" HeaderText="Cause"/> 
                    <telerik:GridBoundColumn DataField="StartDate" HeaderText="Start Date" DataFormatString="{0:d}" DataType="System.DateTime"/> 
                </Columns> 
            </MasterTableView> 
            <PagerStyle AlwaysVisible="true" /> 
            <ClientSettings> 
                <DataBinding Location="WebService.asmx" 
                    SelectMethod="GetEvents" SelectCountMethod="GetEventCount" />                 
            </ClientSettings> 
        </telerik:RadGrid> 

The JSON being returned by the webservice is like so:

{"d":{"__type":"EventDTO","EntityId":"20669908-bf86-4d72-90b0-38239eb6dfa5", 
"Type":{"Name":"Entertainment","Description":"Test","Id":"1228a7b5-43e1-4cd5-b66d-b4afd43004b7",
"CreateDate":"\/Date(1240385834617)\/","LastUpdatedDate":"\/Date(1240385834617)\/","DeletedDate":null,"TimeStamp":[0,0,0,0,0,0,35,152]}, 
"Cause":{"Name":"Global Warming1","Description":"Test","Id":"399fcb2e-0bdc-4e4b-879f-0ee0e97a5db5", 
"CreateDate":"\/Date(1240384333727)\/","LastUpdatedDate":"\/Date(1248085361140)\/","DeletedDate":null,"TimeStamp":[0,0,0,0,0,0,164,19]},"Title":"97979978978","Sites":null,"Location":"Pakistan","Description":"Testing Description \n",
"StartDate":"\/Date(1240574400000)\/","CompletionDate":"\/Date(1246230000000)\/","RequiresVolunteerApproval":false,"Id":"0da73022-7d8d-4f79-a108-61c916a49fe8","CreateDate":"\/Date(1240389765160)\/","LastUpdatedDate":"\/Date(1240389765160)\/","DeletedDate":null,"TimeStamp":[0,0,0,0,0,0,148,192]}} 

Problem is that the Cause column shows up empty. Cause is a nested object inside the main event object...how can I get the radgrid to display nested object's properties?

4 Answers, 1 is accepted

Sort by
0
Haroon
Top achievements
Rank 1
answered on 31 Aug 2009, 02:57 PM
anyone?
0
Haroon
Top achievements
Rank 1
answered on 01 Sep 2009, 06:20 AM
*bump*
0
Haroon
Top achievements
Rank 1
answered on 02 Sep 2009, 10:44 AM
Ok so I tried to flatten out the structure myself at the webservice level, so the webservice method now returns the following string:

{"d":"[{\"Id\":\"20e78338-ffa2-4048-8cc1-05342ac13665\",\"Title\":\"Cause Event\",\"CauseName\":\"Test Cause 21\",\"TypeName\":\"EventType2\",\"StartDate\":\"\\/Date(1247770800000+0500)\\/\",\"CompletionDate\":\"\\/Date(1247943600000+0500)\\/\",\"Location\":\"Timbuktoo\"}]"}

Now the thing is this function is returning a simple string value, whereas I guess radgrid is expecting a JSON object? Is there anyway to get the radgrid to accept this input? Is there anyway we can set the datasource to a javascript function inside the page rather than the webservice itself??
0
Sebastian
Telerik team
answered on 02 Sep 2009, 04:15 PM
Hi Haroon,

The data source passed to the grid when using client-side binding should have JSON signature in order to be recognized as valid by the control. You can use either page methods or web services to supply the source to the grid as explained in this topic from the product documentation.

Regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Haroon
Top achievements
Rank 1
Answers by
Haroon
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or