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

DataSource / Binding to remote data

3 Answers 282 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Engifaar
Top achievements
Rank 1
Engifaar asked on 31 May 2012, 10:17 AM

Hello friends, I'm accessing an ASP.NET WebServices that return JSON. I can see the data correctly from the server to in FireBUG: (See Below)
 I am unable to fill my grid with my URL data returned.. What is my mistake?

var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "WebService.asmx/getAllCustomerName",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json"
            }
        },
        schema: {
            data: function (data) {
                alert(data.d);   /*Data Return Successfully*/
                return data.d;
            }
        },
        error: function (e) {
            alert("Error");
        },
        change: function (e) {
            alert("Change");
        },
        requestStart: function (e) {
            alert("Request Start");
        }
    });


    $("#try").kendoGrid({
        dataSource: dataSource, //No data...
        pageable: true,
        sortable: true,
        height: 450,
        scrollable: { virtual: true },
        selectable: true,
        dataBound: function (e) {
            alert("DataBound");
        },
        columns: [
                    { field: "CustomerID", title: "CustomerID" },
                    { field: "FirstName", title: "FirstName" },
                    { field: "LastName", title: "LastName" },
                    { field: "BalancePoint", title: "BalancePoint" }
                ]
    });


My URL return data of json type:--

{"d":"[{\"BalancePoint\":\"2017.000\",\"CustomerID\":\"000\",\"FirstName\":\"AA\",\"LastName\":\"ZX\"},
{\"BalancePoint\":\"224.000\",\"CustomerID\":\"001\",\"FirstName\":\"AB\",\"LastName\":\"ZY\"},
{\"BalancePoint\":\"1094.000\",\"CustomerID\":\"002\",\"FirstName\":\"AC\",\"LastName\":\"ZZ\"}
]"}

3 Answers, 1 is accepted

Sort by
0
Engifaar
Top achievements
Rank 1
answered on 01 Jun 2012, 02:52 AM
 $("#try").kendoGrid({
        dataSource: dataSource, //Commenting
        dataBound: function (e) {
            alert("DataBound");
        }
});


When i comment "dataSource: dataSource", dataBound event get fired. What is the reason? Please reply anyone..  
0
Paolino
Top achievements
Rank 1
answered on 31 Aug 2012, 02:05 AM
i had the same problem and it tooks one day to realize that the response is actually a json data with one field named "d" with value of a string containing json data.

so the schema.data must tranform data.d string to a json object:

schema: {
    data: function (data) {
        return eval("(" + data.d + ")");
    }
}

0
Sky
Top achievements
Rank 1
answered on 26 Oct 2012, 05:18 AM
thanks ~~~~

very  good  


same  question   ~~~~~  find it  
Tags
Data Source
Asked by
Engifaar
Top achievements
Rank 1
Answers by
Engifaar
Top achievements
Rank 1
Paolino
Top achievements
Rank 1
Sky
Top achievements
Rank 1
Share this question
or