JSON format and the grid

8 posts, 0 answers
  1. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 15 Jan 2012 Link to this post

    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? 


  2. Andrew
    Andrew avatar
    29 posts
    Member since:
    Sep 2010

    Posted 15 Jan 2012 Link to this post

    Is your JSON sample accurate?  It seems to have an unbalanced square brace at the end.
  3. Kendo UI is VS 2017 Ready
  4. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 16 Jan 2012 Link to this post

    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_: {}
     } }

  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 16 Jan 2012 Link to this post

    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!
  6. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 16 Jan 2012 Link to this post

    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_: {}
                                        }
                                    }
                                }
                            });

  7. AngryBill
    AngryBill avatar
    2 posts
    Member since:
    Apr 2009

    Posted 16 Jan 2012 Link to this post

    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. 
  8. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 16 Jan 2012 Link to this post

    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.
  9. Hessner
    Hessner avatar
    189 posts
    Member since:
    Mar 2003

    Posted 18 Jan 2012 Link to this post

    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.

Back to Top
Kendo UI is VS 2017 Ready