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

JSON format and the grid

7 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hessner
Top achievements
Rank 2
Hessner asked on 15 Jan 2012, 06:20 PM
Hi,

My svc request returns:

{"GetRolesResult":{"Roles":{"RowKey":"bf7198e099db4f3eaf62d9f1acd97b69","copy_":false,"delete_":false,"move_":false,"name":"nyrolle","publish_":false,"read_":false,"rename_":false,"write_":false},{"RowKey":"dcbaa08781064d7384558b4049ab6ec9","copy_":false,"delete_":false,"move_":false,"name":"tjekket","publish_":false,"read_":false,"rename_":false,"write_":false},{"RowKey":"fc9be01218c84f219fb72c204bb8ad6a","copy_":false,"delete_":false,"move_":false,"name":"suppe","publish_":false,"read_":false,"rename_":false,"write_":false}]}}

I have tried, inside the schema section, to set:

data: 'GetRolesResult.Roles',

But the grid does still not show any rows at all.

How do I tell the grid where to look for data, inside, the json response? 


7 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 16 Jan 2012, 01:07 AM
Is your JSON sample accurate?  It seems to have an unbalanced square brace at the end.
0
Hessner
Top achievements
Rank 2
answered on 16 Jan 2012, 07:23 AM
Hi,

My correct  pasted Json response are:

{"GetRolesResult":{"Roles":[{"RowKey":"bf7198e099db4f3eaf62d9f1acd97b69","copy_":false,"delete_":false,"move_":false,"name":"nyrolle","publish_":false,"read_":false,"rename_":false,"write_":false},{"RowKey":"dcbaa08781064d7384558b4049ab6ec9","copy_":false,"delete_":false,"move_":false,"name":"tjekket","publish_":false,"read_":false,"rename_":false,"write_":false},{"RowKey":"fc9be01218c84f219fb72c204bb8ad6a","copy_":false,"delete_":false,"move_":false,"name":"suppe","publish_":false,"read_":false,"rename_":false,"write_":false}]}}

Would have expected a Kendo reaction if it was not valid :-)

I am using the standard grid editing.html sample and inserting my own WCF call - the grid becomes visible, but no data are shown.

Here are the schema definition:

schema: { data:  'GetRolesResult.Roles',  
model: { id: "RowKey",
fields: {
RowKey: {},
name: { validation: { required: true} },
 read_: {}
 } }

0
Nikolay Rusev
Telerik team
answered on 16 Jan 2012, 10:25 AM
Hello Bo Hessner,

Can you please show us the DataSource configuration? If you are using setup as in the Grid editing demo your service must return JSONP formatted response and the one that you are showing here is not.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Hessner
Top achievements
Rank 2
answered on 16 Jan 2012, 03:59 PM
Hi, here you go:

I am not familiar with JSONP, but at a quick search I found something about setting: crossDomainScriptAccessEnabled and javascript callback - I am puzzled..
var crudServiceBaseUrl = "http://127.0.0.1:81/domain/rest/RestServiceImpl.svc",
                        dataSource = new kendo.data.DataSource({
                            transport: {
                                read: {
                                    url: crudServiceBaseUrl + "/Roles",
                                    dataType: "jsonp"
                                },
                                update: {
                                    url: crudServiceBaseUrl + "/Roles/Update",
                                    dataType: "jsonp"
                                },
                                destroy: {
                                    url: crudServiceBaseUrl + "/Roles/Destroy",
                                    dataType: "jsonp"
                                },
                                create: {
                                    url: crudServiceBaseUrl + "/Roles/Create",
                                    dataType: "jsonp"
                                },
                                parameterMap: function (options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return { models: kendo.stringify(options.models) };
                                    }
                                }
                            },
                            batch: true,
                            pageSize: 30,
                            schema: {
                                data: 'GetRolesResult.Roles',
                                model: {
                                        id: "RowKey",
                                        fields: {
                                            RowKey: {},
                                            name: { validation: { required: true} },
                                            read_: {}
                                    }
                                }
                            }
                        });

0
AngryBill
Top achievements
Rank 1
answered on 16 Jan 2012, 04:48 PM
I think I am having the same problem.  Not sure what is the problem..  I can see the json data objects coming back from server.  Using firebug to see it and the data looks fine. 
0
Hessner
Top achievements
Rank 2
answered on 16 Jan 2012, 10:12 PM
Hi,

Using fiddler was a success:
//http://127.0.0.1:81/domain/rest/RestServiceImpl.svc/Roles
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "Roles")]
List<RoleMapEntityDto> GetRoles();
//GetRolesResult GetRoles();

1. Had to set WebMessageBodyStyle.Bare - not wrapped.
2. Had to drop my GetRolesResult method(see above) and replace it with a List<>
3. Had to enable JSONP in web.config like this:
<service name="Rest.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
  <endpoint address="" binding="webHttpBinding" contract="Rest.IRestServiceImpl" behaviorConfiguration="web" bindingConfiguration="webHttpBindingWithJsonP" ></endpoint>
</service>

and this:
<bindings>
      <webHttpBinding>
        <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
      </webHttpBinding>
    </bindings>

Now the grid(read) works as exptected.

Must say that it was a lot of work. Had expeced that the grid would accept my JSON reponse as is, and leave it up to me - to point out/define my datastructure in a grid property.

Not sure I will rewrite all services to follow this pattern.
0
Hessner
Top achievements
Rank 2
answered on 18 Jan 2012, 09:06 PM

I was blind.

Dident have to use JSONP. With "plain" JSON I can keep my data response structure as is:

dataSource = new kendo.data.DataSource({
                            transport: {
                                read: {
                                    url: crudServiceBaseUrl + "/Roles",
                                    dataType: "json"
                                },

setting the data property did it:

schema: {
                                data: "Roles",
                                model: {
                                    id: "RowKey",
                                    fields: {

Nice.

Tags
Grid
Asked by
Hessner
Top achievements
Rank 2
Answers by
Andrew
Top achievements
Rank 1
Hessner
Top achievements
Rank 2
Nikolay Rusev
Telerik team
AngryBill
Top achievements
Rank 1
Share this question
or