Hello, I'm having trouble binding my JSON data to my grid when using the transport / schema method. I am able to bind my data to the grid when doing a JSON.parse (data) and manually selecting the datasource.data = data in my grid.
The code I am having trouble with is:
function listView(card) {
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "/Personnel/GetPersonnel",
dataType: "json",
type: "GET",
contentType: "application/json"
}
},
schema: {
model: {
id: "id",
fields: {
firstName: { editable: false },
lastName: { editable: true }
}
}
}
});
$(card).find('.kendo-grid').kendoGrid({
dataSource: dataSource
});
dataSource.read();
}
I have been successful with the following implementation:
function kendoDataAsync(card) {
$(card).find('.kendo-grid').each(function (i, ele) {
var route = "/Personnel/GetPersonnel";
$.getJSON(route).done(function (json) {
var datas = new kendo.data.DataSource({ data: JSON.parse(json) });
var grid = $(ele).data('kendoGrid');
datas.read();
grid.setDataSource(datas);
});
});
}
My JSON data looks like this BEFORE I do JSON.parse, which is where I believe my issue may lie:
"[{\"firstName\":\"Ron\",\"lastName\":\"Roles\",\"id\":\"1\"}]
AFTER a JSON.parse my data is a bit more familiar:
[ {
"firstName":"Ron",
"lastName":"Roles",
"id":1
} ]
Is my schema wrong? Am I not binding correctly?