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

Basic data source config with remote json data

2 Answers 644 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 17 Apr 2012, 09:40 AM
Hi
I am trying to make a basic datasource integration and populate a grid with data.
My RST service delivers JSON in this format
{"country":[
{"codeLong":"AUT","codeShort":"AT","name":"Austria"},
{"codeLong":"BEL","codeShort":"BE","name":"Belgium"},
{"codeLong":"BGR","codeShort":"BG","name":"Bulgaria"}
]}

This is how I try to setup the datasource and Grid:
var ds = new kendo.data.DataSource({
    transport: {
        read: {
        url: "http://localhost:10040/.functions.portlets/services-rest/countriesservice/countriesuk",
        dataType: "json"
            }
        },
    schema: {
        data: "country",
        model: {   
        fields: {
            codeLong: { type: "string" },
            codeShort: { type: "string" },
            name: { type: "string" }
    }
    }
     
    }
});
 
 
                         
 $("#grid").kendoGrid({
          dataSource: ds,
           height: 280,
           scrollable: {
                       virtual: true
                     },
           columns: [
                            { field:"codeLong", title: "codeLong" },
                            { field:"codeShort", title: "codeShort" },
                            { field:"name", title: "name" },
                             
                        ]
                  });
           
            });

I can see the GET request being carried out in FireBug, but the Grid remains empty.
Any suggestions?

I have one further question:
Is it possible to omit the data parameter, and leave out the "root" element?
I would like to be able to read json like this:

[{"codeLong":"AUT","codeShort":"AT","name":"Austria"},
{"codeLong":"BEL","codeShort":"BE","name":"Belgium"},
{"codeLong":"BGR","codeShort":"BG","name":"Bulgaria"}]

/Thomas

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Valchev
Telerik team
answered on 18 Apr 2012, 09:46 AM
Hi Thomas,

Your code snippet looks OK, I tested it in this demo page and it seems to work as expected. Could you please check it and let me know if I missed something?

As for your second question, it is possible to omit the data parameter if your data is not inside a root element. You can see this approach in the above jsFiddle example.

Greetings,
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
Thomas
Top achievements
Rank 1
answered on 19 Apr 2012, 11:51 AM
Thanks for the swift answer.
My problem was that I had an url alias for localhost, so the browser prevented the request (even though it was actually on the same domain)
/Thomas
Tags
Data Source
Asked by
Thomas
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or