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

Grid will not populate from JSON String

1 Answer 360 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 26 Nov 2013, 01:56 AM
I have a kendo grid that I am pulling data from an API (same site)...  I cannot grid to populate with the data.

Here is an example of the json string...

[{"clientID":8,"memoID":14,"memoTime":"2012-05-09T09:04:00","subject":"Letter","memo":"Sent Letter ","initials":"AA","code":1,"private":false,"sticky":false}, ... and so on ...]

The data has no 'structure name' returned so in the schema section below I am not sure what to put?

Here is the code calling the JSON:   (This is from one of your online examples)
<div id="example" class="k-content">
<div id="grid"></div>
  $(document).ready(function() {
                    var grid = $("#grid").kendoGrid({
                        dataSource: {
                               transport: {
                                read: {
                                    url: "/memo/a/8/b/1",
                                    dataType: "json",
               
                                }
                            },
                            schema: {
                                data: function (response) {
                                    return response.data; 
                                }
                          
                            },
                            pageSize: 20,
                            serverPaging: true,
                            serverSorting: true,
                            serverFiltering: true
                        },
                        toolbar: kendo.template($("#template").html()),
                        height: 430,
                        sortable: true,
                        pageable: true,
                        columns: [
                            { field: "MemoID", title: "MemoID", width: 100 },
                            { field: "Subject", title: "Subject" },
                            { field: "Initials", title: "Initials", width: 100 },
                            { field: "Memo", title: "Memo" }
                        ]
                    });

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 26 Nov 2013, 01:23 PM
Hi Bob,

The problem is caused by the data function defined in the schema of the data source. The response you are returning doesn't have a "data" field which your function seems to expect. Removing the schema declaration should resolve the problem. Also make sure the field specified in the column definition is the same as in the JSON. Right now the casing is wrong - "memoID" vs. "MemoID"

Here is a live demo showing a working configuration: http://jsbin.com/eXOLAJe/1/edit


Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Bob
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or