But how do you define a model for an object which has as one of its properties an array or list of objects? For example you might have orders with order items.
[
{
OrderId: 1,
OrderName:
'order 1'
OrderItems: [
{
ProductId: 1,
ProductName:
"sample name"
},
{
ProductId: 2,
ProductName:
"sample name 2"
}
},
{
OrderId: 2,
OrderName:
'order 2'
OrderItems: [
{
ProductId: 55,
ProductName:
"sample name 55"
},
{
ProductId: 18,
ProductName:
"sample name18"
}
}
]
var
model = kendo.data.Model.define({
id:
"OrderId"
,
fields: {
OrderId: {
type:
"number"
,
editable:
false
},
OrderName: {
type:
"string"
,
editable:
false
},
OrderItems: {
??????????????
}
}
});
In other scenarios this might be where you want to make this field editable so that the user can select a different product, or a category or whatever the field would be.
Thanks.
12 Answers, 1 is accepted
The dataSource is designed to operate with flat data which is why there is no specified type for 'object' or 'array'. If your requirement is to support such scenario, please leave the type option undefined and set the defaultValue of the field like in this demo (category field).
Regards,
Alexander Valchev
Telerik
What you need to do is as follows:
Users: [{ UserId: { type:
"number"
},UserName: { type:
"string"
} }],
Hello Per,
the current thread is fairly outdated. I may suggest that you open a new one or post a support ticket if you need assistance with a similar issue.
Regards,Petyo
Telerik
Hello Mike,
the original question in this thread was addressed in the response from Alexander, and the statement he provided still holds true. The last two replies do not seem to be related to the topic, unless I am missing something. Perhaps the authors may say more.
Regards,
Petyo
Telerik
Hi,
You say this thread might be out of date, however I found it via a google search .and I'm sure others with the same question will too.
It would have been nice if you had just answered the original posters question, specifying if the information provided by "Gal" is correct or not? Or specify an alternate way in which to specify complex types.
From reading this thread it appears you can not specify complex types, so is this correct?
The answer from Gal does not contain an runnable example, so I am afraid that I can't confirm what was his intention. Apart from that, like my previous post suggests, the DataSource does not support complex types.
Regards,
Petyo
Telerik
Are complex data types still not supported? I've obtained success with a nested model type. However, I commented out the validation because my controls limited the output to where validation was unnecessary.
see below:
model: {
id:
"iD"
,
fields: {
id: { type:
"number"
},
description: { type:
"string"
, defaultValue:
"[New Thing]"
, nullable:
false
, validation: { required:
"Please enter a description for this new thing."
} },
active: { type:
"boolean"
, defaultValue:
true
},
schedule: {
defaultValue: { id: 0, interval: 1, frequency: 4, start:
new
Date(), end:
null
, immediate:
false
, indefinite:
true
}
//,
/* validation: {
validInterval: function (input) {
if (input.is("[name=interval]")) {
input.attr("data-validInterval-msg", "Interval must be positively numeric.");
return $(input).val() > 0 && !isNaN($(input).val()) && Number.isInteger($(input).val());
}
return true;
}
}*/
},
recipients: { defaultValue: [] },
reports: { defaultValue: [] },
subject: { type:
"string"
, defaultValue:
"new subject"
, validation: { required:
"Please enter an email subject for this thing."
} },
nextRunTime: { type:
"string"
, defaultValue:
""
},
displayRecipients: { type:
"string"
, defaultValue:
""
},
displayReports: { type:
"string"
, defaultValue:
""
},
displayInterval: { type:
"string"
, defaultValue:
""
},
displayStatus: { type:
"string"
, defaultValue:
""
}
}
}
Working with complex data is supported, but it has its limitations.
For example, our demo with a custom editor is showing how to bind and to edit complex objects:
http://demos.telerik.com/kendo-ui/grid/editing-custom
Currently, some of the main limitations are when it comes to sorting, filtering and grouping as the DataSource can make these operations only over flat data.
Regards,
Stefan
Progress Telerik
Been looking for the solution lately and I stumbled on this page and I am guessing the answer still hasn't changed. For those who are looking for a solution, someone from Stackoverflow has posted a solution. It works, I have implemented in my application.
Here's the catch, it is very slow. At least for my application it is, it would be nice if Kendo would officially support and optimized way of filtering the complex data types.
Thank you for sharing the example with the community.
As for a future support, I can suggest submitting a feature request and based on its popularity we may implement it in a future release:
http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback
Regards,
Stefan
Progress Telerik