I have json returning from an API that is not consistant, meaning some records have "age" associated with them while others do not.
I am trying to populate a Kendo UI Grid in order to display/manipulate the data. Unfortunately, when the records that do not have "Age" associated with them return with records that do, kendo breaks down with an error: Uncaught ReferenceError: Age is not defined
Here is the example of the working grid: http://jsfiddle.net/tmort/CVkpF/
And here is the grid with one record returning without "Age": http://jsfiddle.net/tmort/CVkpF/1/ - You can see the error appear in the Console, not on the page itself.
Is there any way I can make the grid dynamic enough to understand that age hasn't returned, set it to null, and then continue on?
Code I'm using:
var data = [
{
FirstName: 'John',
LastName: 'Doe',
City: 'New York City',
Title: 'Supervisor',
BirthDate: '1/1/1975',
Age: '37',
},
{
FirstName: 'Jane',
LastName: 'Doe',
City: 'Buffalo',
Title: 'Sales Associate',
BirthDate: '1/1/1980',
}
]
$(document).ready(function() {
var grid = $("#grid").kendoGrid({
dataSource: {
data: data,
schema: {
model: {
fields: {
FirstName: { type: "string" },
LastName: { type: "string" },
City: { type: "string" },
Title: { type: "string" },
BirthDate: { type: "date" },
Age: { type: "number" }
}
}
},
pageSize: 10
},
height: 500,
scrollable: true,
sortable: true,
selectable: true,
filterable: true,
pageable: true,
columns: [
{
field: "FirstName",
title: "First Name"
},
{
field: "LastName",
title: "Last Name"
},
{
field: "City"
},
{
field: "Title"
},
{
field: "BirthDate",
title: "Birth Date",
template: '#= kendo.toString(BirthDate,"MM/dd/yyyy") #'
},
{
field: "Age"
}
]
}).data("kendoGrid");
});
Any help greatly appreciated. Thanks!