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

9 posts, 0 answers
  1. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 12 Nov 2013 Link to this post

    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.
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 15 Nov 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Gal
    Gal avatar
    48 posts
    Member since:
    Apr 2009

    Posted 28 Nov 2014 in reply to Alexander Valchev Link to this post

    This is not correct as to the current date 
    What you need to do is as follows: 

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

  5. Per
    Per avatar
    3 posts
    Member since:
    Apr 2015

    Posted 18 Aug 2015 in reply to Gal Link to this post

    And where did you find documentation on the new format?
  6. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 20 Aug 2015 Link to this post

    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!
     
  7. Mike
    Mike avatar
    4 posts
    Member since:
    May 2013

    Posted 02 Nov 2015 in reply to Petyo Link to this post

    @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.
  8. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 04 Nov 2015 Link to this post

    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!
     
  9. David
    David avatar
    3 posts
    Member since:
    Oct 2015

    Posted 25 Jan Link to this post

    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?

     

     

  10. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 28 Jan Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready