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

Issue Creating Kendo UI Grid Model with Navigation Property

1 Answer 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
None
Top achievements
Rank 1
None asked on 05 May 2015, 07:25 PM
 I am using the kendo ui grid and am trying to add CRUD operations for my model that has some navigation properties. Here is my schema:
schema: {
data: function (data) { 
return data || [];
},
model: {
id: "Id",
fields: {
Id: { editable: false,
nullable: false,
type: "number"
},
Frequency: { type: "string" },
FREQ_POOL: { type: "object" },//THIS IS A NAVIGATION IN MY MODEL

}
}

}


And here is my grid:

$("#AFTRCCFreqGrid").kendoGrid({
dataSource: AFTRCCDS,

columns: [
// { field: "Id", title: "Freq ID", format: "{0:c}", width: "120px" },
{ field: "Frequency", title: "Frequency", editor: categoryDropDownEditor, format: "{0:c}", width: "120px" },
{ field: "FREQ_POOL.Comments", title: "Comments", format: "{0:c}", width: "120px" },
{ command: ["edit", "destroy"], title: " ", width: "250px" }
],
toolbar: ["create"],
editable: "inline",
pageable: true

});

When I hit the "Add New Record Button" in the kendo grid, I get the following error:Uncaught TypeError: Cannot read property 'Comments' of undefined(anonymous function). Now here is the thing. I manually added a row to my SQL table, and I can use the kendo grid to UPDATE the row successfully. I can edit the navigation property "Comments".

But for some reason, when I create a new row, I cannot get it to work.My guess is that when I load the table it loads the navigation properties, but when I hit "Add New Record", it doesn't know how to create the navigation property "From scratch", whereas when I update a row it already has the navigation property info loaded.Any ideas how I would go about fixing this? Thank you.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 May 2015, 11:31 AM
Hello,

The error will be thrown because the value will be null for new items. You can avoid it by setting default value for the field e.g.
FREQ_POOL: {
    type: "object",
    defaultValue: {}
}


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
None
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or