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

Binding to JSON only containing list of values, not dictionary

2 Answers 110 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 11 Jul 2012, 12:12 AM
I have a remote json datasource which comes in as follows:

[["Advantage", null, "2012-05-07T01:54:02.130000", "sqlsvrautosysjobs", "2012-05-07T01:54:02.130000", "sqlsvrautosysjobs", 1], ["ALDOP", null, "2012-05-07T01:54:02.130000", "sqlsvrautosysjobs", "2012-05-07T01:54:02.130000", "sqlsvrautosysjobs", 1]]

How can I bind my datasource to this?  I cannot change the datasource so I will need to use ordinal references or something like that.  I've tried the following with no luck:

$("#grid").kendoGrid({
    dataSource: {
        type: "json",
        transport: {
            read: {
                url: 'list',
                dataType: 'json',
                contentType: 'application/json'
            }
        },
        schema: {
            model: {
                fields: {
                    SourceSystem: { type: "string" },
                    ModifiedComment: { type: "string" },
                    CreatedDate: { type: "date" },
                    ModifiedDate: { type: "date" },
                    ModifiedUser: { type: "string" },
                    Version: { type: "number" }
                }
            }
        },
        pageSize: 10,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    },
    height: 250,
    filterable: true,
    sortable: true,
    pageable: true,
    columns: [{
            field:"SourceSystem",
            title: "Source"
        }, {
            field: "ModifiedComment",
            title: "Comment",
            filterable: false
        },
        "Version",
        {
            field: "CreatedDate",
            title: "Created Date",
            width: 100,
            format: "{0:MM/dd/yyyy}"
        }, {
            field: "ModifiedDate",
            title: "Modified Date",
            width: 100,
            format: "{0:MM/dd/yyyy}"
        }, {
            field: "ModifiedUser",
            title: "Modified By"
        }
    ]
});

Any ideas?

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 11 Jul 2012, 07:32 AM
Hi Darren,

You need to convert that data to a format which the DataSource can understand. Here is how: http://jsbin.com/ibatex/edit#javascript,html 

 The key is to use the parse method of the schema:

parse: function(raw) {
     var result = [];
             
     for (var i = 0; i < raw.length; i++) {
        result.push( {
            SourceSystem: raw[i][0],
            ModifiedComment: raw[i][1],
            CreatedDate: raw[i][2],
            ModifiedDate: raw[i][4],
            ModifiedUser: raw[i][5],
            Version: raw[i][6]
         });
    }
          
    return result;
},

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Darren
Top achievements
Rank 1
answered on 11 Jul 2012, 07:02 PM
Hi Atanas,

That worked perfect; thanks for such a clear solution!
Tags
Data Source
Asked by
Darren
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Darren
Top achievements
Rank 1
Share this question
or