DataSource / Binding to remote data

4 posts, 0 answers
  1. Engifaar
    Engifaar avatar
    15 posts
    Member since:
    May 2012

    Posted 31 May 2012 Link to this post

    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\"}
    
    ]"}
  2. Engifaar
    Engifaar avatar
    15 posts
    Member since:
    May 2012

    Posted 31 May 2012 Link to this post

     $("#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..  
  3. Paolino
    Paolino avatar
    2 posts
    Member since:
    Aug 2012

    Posted 30 Aug 2012 Link to this post

    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 + ")");
        }
    }

  4. Sky
    Sky avatar
    1 posts
    Member since:
    Jan 2012

    Posted 26 Oct 2012 Link to this post

    thanks ~~~~

    very  good  


    same  question   ~~~~~  find it  
Back to Top