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

JSON format from backend not loading in Data Source

2 Answers 229 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Zach
Top achievements
Rank 1
Zach asked on 10 Apr 2012, 06:50 PM
I am testing a REST call from my server to load a Data Source, and my REST service returns the JSON data like this:

{"person":[{"address":"Address1","name":"Person1"},{"address":"Address2","name":"Person2"},{"address":"Address3","name":"Person3"}]}

This has been okay for some other frameworks I'm testing, with the use of a "root" setting that tells the datasource to grab the JSON object that is "person".

Here is my Kendo code:

$(document).ready(function() {
 
   $("#grid").kendoGrid({
      dataSource: {
         transport: {
            read: {
               url: myURLFunc(),
               dataType: "json"
            }
         },
         schema: {
            model: {
               fields: {
                  name: {},
                  address: {}
               }
          }
      }
   },
   height: 250,
   sortable: true,
   columns: [
      {
         field: "name",
         title: "Person"
      },
      {
         field: "address",
         title: "Address"
      }
      ]
   });
});

Is there anything I can do differently to have the Kendo Data Source load the JSON I currently have?

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 11 Apr 2012, 09:30 AM
Hello Zach,

I believe that you are looking for the data option of the schema. In order to define the root object that contains the array of your data, you configuration should be similar to:
schema: {
    data: "person",
    model: {
        fields: {
            //your fields declaration
        }
    }
}


Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Zach
Top achievements
Rank 1
answered on 11 Apr 2012, 03:59 PM
Thanks for the help!  That worked.

I pieced together a solution late yesterday which was to manipulate the parse function like this:

schema : {
       parse : function(data) {
              return data.person;
       }
}

But I like your way better, I missed the "data" config item, because in the API it says its a function.

Thanks Again!
Tags
Data Source
Asked by
Zach
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Zach
Top achievements
Rank 1
Share this question
or