0 Replies Latest reply on May 5, 2014 11:31 PM by Shraddha Prajapati

    How to retrieve fields value from Kendo Grid Models

    Shraddha Prajapati

      Hi i want to retrieve fields value from Kendo Grid Models...

      I try to get it but not retrieve records in the Kendo.....Bellow is my code:

      Service.cfc

      component

      {

        remote string function JsonRead() returnFormat="plain" output="false"

        {

        q = new Query();

        q.setdataSource("TestingDataSource");

        q.setsql("SELECT * FROM Product");

        qResult = q.execute().getresult();

        return serializeJSON(queryToStruct(qResult));

        }

        struct function queryToStruct(required query data) output="false"

        {

        result = {};

        columns = listToArray(arguments.data.columnList);

       

        for(r = 1; r <= arguments.data.recordCount; r++)

        {

        row = {};

       

        for(c = 1; c <= arrayLen(columns); c++)

        {

        columnName = columns[c];

        structInsert(row, columnName, arguments.data[columnName][r]);

        }

       

        structInsert(result, r, row);

        }

       

        if(structCount(result) == 1)

        {

        result = result[structKeyArray(result)[1]];

        }

        return result;

        }

      }

      index.xfm

      <!DOCTYPE html>

      <html>

        <head>

        <title>

        Untitled Document

        </title>

        <script src="Scripts/jquery-1.10.2.js">

        </script>

        <script src="Scripts/jquery-ui.js">

        </script>

        <script src="Scripts/kendo.all.min.js">

        </script>

        <link href="Styles/jquery-ui.css" type="text/css" rel="stylesheet">

        <link href="Styles/kendo.common.min.css" type="text/css" rel="stylesheet">

        <link href="Styles/kendo.default.min.css" type="text/css" rel="stylesheet">

        </head>

        <body>

        <div id="grid">

        </div>

        <span id="loadLink">

        Load Query

        </span>

        <script>

        debugger;

        $("#loadLink").click(function(e){

              var serviceURL = "Component/Service.cfc?method=",

              dataSource = new kendo.data.DataSource({

               transport: {

           

                   read: {

                    type: "POST",

                       url: serviceURL + "JsonRead",

                       dataType: "JSON"

                   },

                parameterMap: function(options, operation)

        {

                      if (operation !== "read" && options.models)

        {

                          return {models: kendo.stringify(options.models)};

                      }

                  }

               },

           

               batch: true

           });

       

           $("#grid").kendoGrid({

               dataSource: dataSource,

               pageable: true,

               height: 430,

               toolbar: ["create"],

               columns: [{

                   field: "ProductId",

                   title: "ProductId",

                   format: "{0:c}",

                   width: "100px"

               }, {

                   field: "ProductCategory",

                   title: "ProductCategory",

                   width: "100px"

               }, {

                   field: "ProductName",

                   width: "100px"

               }, {

                   command: ["edit", "destroy"],

                   title: " ",

                   width: "172px"

               }],

               editable: "inline"

           });

        });

        </script>

        </body>

      </html>

       

      Message was edited by: Shraddha Prajapati

       

      i got

      serializeJSON(queryToStruct(qResult)) =   {"2":{"PRODUCTNAME":"2014 Chevrolet Cruze Diesel 4dr Sedan (2.0L 4cyl Turbodiesel 6A)","PRODUCTCATEGORYID":1,"PRODUCTID":2},"1":{"PRODUCTNAME":"2014 Kia Cadenza Premium 4dr Sedan (3.3L 6cyl 6A)","PRODUCTCATEGORYID":1,"PRODUCTID":1}}

       

      But i want

      serializeJSON(queryToStruct(qResult)) =   [{"ProductId":3,"ProductCategoryId":1,"ProductName":"2013 BMW M6 2dr Coupe (4.4L 8cyl Turbo 7AM)"},{"ProductId":12,"ProductCategoryId":1,"ProductName":"2013 Nissan GT-R Premium 2dr Coupe AWD (3.8L 6cyl Turbo 6AM)"}]