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

Why doesn't JSON from my service appear in my grid?

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 04 Oct 2012, 05:56 PM
I'm attempting to populate the Kendo UI Grid with JSON returned from my web service (ASP.NET Web API). The JSON appears valid, confirmed valid by running the entire return through JSONLint.com.

Here is a sample from the service:
[{"Id":2000,"Name":"Alabama"},{"Id":2001,"Name":"Alaska"},{"Id":2002,"Name":"Arizona"}]

The problem is, the data returned from the service does not display in the grid. If I comment out the call to the service and use the array created below, the grid is populated. What's going on and how do I fix it?

The code below is my entire demo page.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Basic Grid usage</title>
    <link href="content/kendo/2012.2.710/kendo.common.min.css" rel="stylesheet" type="text/css">
    <link href="content/kendo/2012.2.710/kendo.default.min.css" rel="stylesheet" type="text/css">
    <script src="scripts/kendo/2012.2.710/jquery.min.js" type="text/javascript"></script>
    <script src="scripts/kendo/2012.2.710/kendo.web.min.js" type="text/javascript"></script>
</head>
<body>
 
    <div id="states">
    </div>
    <script type="text/javascript">
 
        $(document).ready(function () {
 
            var states = [
                    { Id: 1, Name: "Maine" },
                    { Id: 2, Name: "Washington" },
                    { Id: 3, Name: "Idaho" }
                ];
 
            var statesDataSource = new kendo.data.DataSource({ data: states });
 
//            var statesDataSource = new kendo.data.DataSource({
//                transport: {
//                    read: {
//                        url: "http://XXX.com/apps/states",
//                        dataType: "jsonp"
//                    }
//                }
//            });
 
            statesDataSource.read();
 
            $("#states").kendoGrid({
                dataSource: statesDataSource
            });
        });
    </script>
</body>
</html>

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 05 Oct 2012, 01:43 PM
Hi Scott,

JSONP data should be wrapped in a function call. It this the case in your application?

Please compare your Grid datasource implementation and server response with the ones here:

http://demos.kendoui.com/web/datasource/remote-data.html

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