geethu
geethu

Reputation: 98

Bind json data to kendo grid

I have to bind the Result of a web API(post) call to a kendo grid. The result format is

{
  "Id": 121,
  "referenceId": 18222,
  "status": null,
  "message": "Completed"
}

API call is :

            read: {
                url: //url,
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
            },
            parameterMap: function () {
                return JSON.stringify({ Active: false });
            }
        },
        schema: {
           data:'data'
        }

Bind :

$("#grid").kendoGrid({

          dataSource: dataSource
           columns: [{
                        field: "Id",
                        title: "Id"
                    }]
});

But its not working. :(

Upvotes: 0

Views: 626

Answers (1)

Rajdeep
Rajdeep

Reputation: 802

Use kendo.all.min file in reference.

use this dataSource part

schema: {
                  model: {
                       id: "Id",
                      fields: {                                      
                          Id: {  },
                          referenceId: { },
                          status: { },
                          message: {} 
                     }
                  }
              }

use this at grid side

      $("#grid").kendoGrid({
          dataSource: [{
              "Id": 121,
              "referenceId": 18222,
              "status": "test",
              "message": "Completed"
          }],
          navigatable: true,
          pageable: true,
          height: 550,
          toolbar: ["create", "save", "cancel"],
          columns: [
               { field: "Id", title: "Unit Price" },
                { field: "referenceId", title: "Units In Stock" },
                { field: "status", width: 120 },
                { field: "message", width: 120 }
          ],
          editable: true
      });

Upvotes: 1

Related Questions