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

Model - complex model with nested objects, or list of objects

12 Answers 3332 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jacques
Top achievements
Rank 2
Jacques asked on 13 Nov 2013, 05:30 AM
The documentation at the URL http://docs.kendoui.com/api/framework/model describes four data types namely: "string", "date", "number" and "boolean". 

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"
        }
}
]
In this case the kendo model would look as follows: 
var model = kendo.data.Model.define({
    id: "OrderId",
    fields: {
        OrderId: {
                type: "number",
                editable: false
        },
 
        OrderName: {
                type: "string",
                editable: false
        },
 
        OrderItems: {
            ??????????????
        }
    }
});
What would the type be for 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

Sort by
0
Alexander Valchev
Telerik team
answered on 15 Nov 2013, 08:54 AM
Hello J.Hoventer,

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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gal
Top achievements
Rank 2
answered on 28 Nov 2014, 06:47 PM
This is not correct as to the current date 
What you need to do is as follows: 

Users: [{ UserId: { type: "number" },UserName: { type: "string" } }],

0
Per
Top achievements
Rank 1
answered on 18 Aug 2015, 08:48 PM
And where did you find documentation on the new format?
0
Petyo
Telerik team
answered on 20 Aug 2015, 09:19 AM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Justin
Top achievements
Rank 1
answered on 02 Nov 2015, 03:46 PM
@Petyo Or maybe you could provide an update showing how to handle this scenario currently, as well as a link to the latest documentation... just a thought.
0
Petyo
Telerik team
answered on 04 Nov 2015, 08:37 AM

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
David
Top achievements
Rank 1
answered on 26 Jan 2016, 02:23 AM

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?

 

 

0
Petyo
Telerik team
answered on 28 Jan 2016, 06:24 AM
Hello,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Paul
Top achievements
Rank 1
answered on 06 Sep 2017, 08:24 PM

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: "" }
                }
            }
0
Stefan
Telerik team
answered on 08 Sep 2017, 11:45 AM
Hello Paul,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ehtesham
Top achievements
Rank 1
answered on 20 Nov 2017, 03:52 PM

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.

0
Stefan
Telerik team
answered on 22 Nov 2017, 08:44 AM
Hello, Ehtesham,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Data Source
Asked by
Jacques
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Gal
Top achievements
Rank 2
Per
Top achievements
Rank 1
Petyo
Telerik team
Justin
Top achievements
Rank 1
David
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Stefan
Telerik team
Ehtesham
Top achievements
Rank 1
Share this question
or