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

fill out kendogrid

4 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
totoro
Top achievements
Rank 1
totoro asked on 25 Sep 2012, 02:00 PM

Hi!

I can't load information in json format in my KendoGrid... 
url : http://dotnet.habitatpro-com.local/test.json  return json flux
CODE:
<html>
<head>
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="Scripts/kendo.all.js"></script>

</head>
<body>
            <div id="example" class="k-content">
            <div id="grid"></div>

            <script type="text/javascript">
                $(document).ready(function () {
                    var crudServiceBaseUrl = "http://dotnet.habitatpro-com.local/test.json",
                        dataSource = new kendo.data.DataSource({
                            transport: {
                                read: {
                                    url: crudServiceBaseUrl,
                                    dataType: "jsonp"
                                },
                                parameterMap: function (options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return { models: kendo.stringify(options.models) };
                                    }
                                }
                            },
                            batch: true,
                            pageSize: 30,
                            schema: {
                                model: {
                                    id: "ProductID",
                                    fields: {
                                        ProductID: { editable: false, nullable: true },
                                        ProductName: { validation: { required: true} },
                                        UnitPrice: { type: "number", validation: { required: true, min: 1} },
                                        Discontinued: { type: "boolean" },
                                        UnitsInStock: { type: "number", validation: { min: 0, required: true} }
                                    }
                                }
                            }
                        });

                    $("#grid").kendoGrid({
                        dataSource: dataSource,
                        pageable: true,
                        height: 400,
                        toolbar: ["create"],
                        columns: [
                            { field: "ProductName", title: "Product Name" },
                            { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "150px" },
                            { field: "UnitsInStock", title: "Units In Stock", width: "150px" },
                            { field: "Discontinued", width: "100px" },
                            { command: ["edit", "destroy"], title: "&nbsp;", width: "210px"}],
                        editable: "popup"
                    });
                });
            </script>
        </div>
</body>
</html>


Do you have any suggestions ?

Thanks

4 Answers, 1 is accepted

Sort by
0
OnaBai
Top achievements
Rank 2
answered on 26 Sep 2012, 09:59 PM
Try defining an error and success functions that display information about the problem (or not).
I.e.: In the Datasource add:
success: function(result) {
    alert("Success");
},
error: function(info) {
    alert("Error!");
    console.log("info", info);
},
and check what your browser console shows about the error.
0
totoro
Top achievements
Rank 1
answered on 27 Sep 2012, 12:44 PM
Hi OnaBai,

Thank you for your answer
Error on firebug console :
errorThrown     Error: jQuery18209097495959869581_1348749079551 was not called       
throw new Error( msg );  jquery-1.8.2.js (line 477)

This method vb return json flux:


    <WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Sub ReturnJsonTest()
        Dim strbdd As Object = "[{""ProductID"":1,""ProductName"":""Chai"",""UnitPrice"":18,""UnitsInStock"":39,""Discontinued"":false},     {""ProductID"":2,""ProductName"":""Chang"",""UnitPrice"":19,""UnitsInStock"":17,""Discontinued"":false},{""ProductID"":3,""ProductName"":""Aniseed Syrup"",""UnitPrice"":10,""UnitsInStock"":13,""Discontinued"":false},{""ProductID"":4,""ProductName"":""Chef Anton\u0027s Cajun Seasoning"",""UnitPrice"":22,""UnitsInStock"":53,""Discontinued"":false}]"
        Context.Response.ContentType = "application/json"
        Context.Response.Write(strbdd)
        Context.Response.End()
    End Sub


I really don't see where is the problem .. callback maybe?
Thanks for investigating
0
OnaBai
Top achievements
Rank 2
answered on 27 Sep 2012, 12:51 PM
You say: "This method vb return json flux" and Context.Response.ContentType = "application/json"
But you datasource says jsonP.  Is your datatype JSON or JSONP?


0
totoro
Top achievements
Rank 1
answered on 27 Sep 2012, 01:47 PM
When i use "application/jsonp" i have the same problem with error in firebug console...and there is a window which propose if i want download my json flux... =_='
Tags
Grid
Asked by
totoro
Top achievements
Rank 1
Answers by
OnaBai
Top achievements
Rank 2
totoro
Top achievements
Rank 1
Share this question
or