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

Having trouble getting grid to populate from data source

1 Answer 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
PaulMrozowski
Top achievements
Rank 1
PaulMrozowski asked on 03 Apr 2012, 10:25 PM
I have a grid that I want populated from a JSON callback. I also want pop-up editing. I see the callback occur to retrieve the data, but the grid isn't populated with it.

Here's a sample of the JSON result:
[{"AddedOn":"\/Date(1333241309627-0400)\/","Batch":"20120331-A","Comment":"Sample","User":"paulm"}]

I see the grid appear, and I get the button to add a new item (and the pop-up appears).
Secondary question: How do I control which fields are displayed in the pop-up? I don't see a list of options available for each field in the help (are they documented someplace?). 

$(function () {
    var dataSource = new kendo.data.DataSource({
        type: 'jsonp',
        transport: {
            read: {
                url: '/api/BatchApi/GetOpenBatchList',
                dataType: 'jsonp'
            },
            update: {
                url: '/api/BatchApi/Update',
                dataType: 'jsonp'
            },
            destroy: {
                url: '/api/BatchApi/Delete',
                dataType: 'jsonp'
            },
            create: {
                url: '/api/BatchApi/Create',
                dataType: 'jsonp'
            }
        },
        batch: true,
        pageSize: 30,
        schema: {
            model: {
                id: "Batch_ID",
                fields: {
                    Batch_ID: { editable: false, nullable: false },
                    Batch: { validation: { required: true} },
                    AddedOn: { type: "date", editable: false },
                    User: { editable: false },                       
                    Comment: { type: "string" }
                }
            }
        }
    });
 
    $("#batchGrid").kendoGrid({
        dataSource: dataSource,
        scrollable: true,
        sortable: true,
        selectable: 'row',
        toolbar: [{ name: 'create', text: 'New Batch'}],
        columns: [
                    { field: "Batch", title: "Batch" },
                    { field: "AddedOn", title: "Added On" },
                    { field: "User", title: "User" },
                    { command: ["edit"], title: " ", width: "100px" }
                 ],
        editable: "popup"
    });
});

The HTML is a basic div tag w/ID. <div id="batchGrid"></div>

I'm not seeing any JS errors. Just an empty grid. What am I missing?



1 Answer, 1 is accepted

Sort by
0
PaulMrozowski
Top achievements
Rank 1
answered on 05 Apr 2012, 01:45 AM
So apparently the JSON result needs to look like this:

{"total":1,"data":[{"Batch_ID":1,"Batch":"20120331-A","AddedOn":"\/Date(1333241309627)\/","User":"paulm","Comment":"Sample"}]}

and you need to specify:
data: "data"

inside of the schema tag. 
Tags
Grid
Asked by
PaulMrozowski
Top achievements
Rank 1
Answers by
PaulMrozowski
Top achievements
Rank 1
Share this question
or