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

Binding Grid to local Json

3 Answers 211 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 27 Aug 2013, 07:49 AM
Hello,
    I'm trying to build a grid by retrieving the data from a JSON object, but I can't crearly get how to do it.

I would like to define the Grid in C# with no data model specified and then defining the model(columns) and populating the rows at client-side time. Is it possible or it's just senseless?

I can't find clear examples on how to build the grid from a Json, could I have some?

Thanks anticipately

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 29 Aug 2013, 05:38 AM
Hello,

This is not supported. The columns should be specified on initialization. If the model should be determined on the client then you should use the JavaScript initialization.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sreedhar
Top achievements
Rank 1
answered on 08 Oct 2013, 09:11 PM
Hello Kendo Team

I am having difficulties in binding json data (local) to the kendo grid. I am getting the grid headers, but not the data. Please let me know where is the issue in binding the json data.

HTML data (aspx file)
----------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="grid.aspx.cs" Inherits="KendoUIPOC.tryouts.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Kendo UI Grid - JSON</title>
   <link rel="stylesheet" href="../styles/kendo.common.min.css" type="text/css">
   <link rel="stylesheet" href="../styles/kendo.default.min.css">
   <link rel="stylesheet" href="../styles/temp.css">
   <script src="../js/jquery.min.js"></script>
   <script src="../js/kendo.all.min.js"></script>
</head>
<body>

    <div id="grid"></div>
    
    <script>
    
    $(function() {
     var dsource=new kendo.data.DataSource({
       transport: {
         read: {
           url: "dataobj.json",
           dataType: "json"         
         }
       }     
     });
     
     $("#grid").kendoGrid({
       dataSource: dsource,
       columns: [
        { name: "patient", title: "Patient" },
        { name: "gender", title: "Gender" },
        { name: "dob", title: "DOB" },
        { name: "healthPlan", title: "Health Plan" },
        { name: "phone", title: "Phone Number" },
        { name: "pcp", title: "PCP" },
        { name: "status", title: "Overall Status" },
        { name: "patientID", title: "McK Patient ID" }

],
       height: 340,
       scrollable: true,
       sortable: true,
       pageable: true
     
     });
    
    });    
    </script>

</body>
</html>


JSON File
----------------

[
   {"patient" : "Apple, Margaret", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Medicare", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 328239 },
   {"patient" : "Bregstrom, Glen", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Bruno, Alan", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Collier, Kasey", "gender" : "Female", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Edelson, Ted", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Green, Lousie", "gender" : "Female", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Green, Sarah", "gender" : "Female", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Grill, Whilly", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Grosse, Vincent", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Gullat, Jack", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Gust, Emilo", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Harte, Llyod", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Hasley, Angel", "gender" : "Female", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Henline, Rene", "gender" : "Female", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 },
   {"patient" : "Hernandez, Robert", "gender" : "Male", "dob" : "09/30/1945", "healthPlan" : "Elder Care Frail Elderly", "phone" : "(781) 555-0131", "pcp" : "Dr. Karen Johnson", "status" : "Red", "patientID" : 235353 }
 ]
0
Daniel
Telerik team
answered on 10 Oct 2013, 11:30 AM
Hello,

The correct configuration name for the column property name is field:

columns: [
    { field: "patient", title: "Patient" },
    ...
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Michele
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Sreedhar
Top achievements
Rank 1
Share this question
or