Properties defined on ObservableObject are lost when wrapped in DataSource object and schema.model is specified

4 posts, 0 answers
  1. Michelle
    Michelle avatar
    33 posts
    Member since:
    Feb 2015

    Posted 20 Jul 2015 Link to this post

    I am using Typescript to define objects that extend the kendo.data.ObservableObject type.  These objects contain getter and setter properties.  When I pass an array of these ObservableObject-derived objects into the DataSource data property and when I specify a schema.model value, I lose all the getter and setter properties on my objects, such that the grid does not display any values properly.  The only fields left available in the DataSource object are the private properties.  I made an example here:

     http://dojo.telerik.com/ozuHI

     Please comment out the commented section at the bottom to see the problem occur.

     The PersonDTO definition in my example is the same code that gets generated by Typescript when I define a class that extends kendo.data.ObservableObject in Typescript.  The getters and setters are defined on PersonDTO.prototype rather than on PersonDTO itself and I suspect that is the source of the problem.  Internally, DataSource seems to be ignoring properties that are not found on PersonDTO directly whenever it wraps an object in a model object.

     I would appreciate any ideas for workarounds or a bug fix.  Thanks!

  2. Daniel
    Admin
    Daniel avatar
    2118 posts

    Posted 22 Jul 2015 Link to this post

    Hello Michelle,

    You should use the dataSource model type for the objects in order to avoid the problem. if you define the schema model then the dataSource objects will not be simply ObservableObjects but will be instances of kendo.data.Model. I updated the example to demonstrate how to use the same type.

    Regards,
    Daniel
    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. Michelle
    Michelle avatar
    33 posts
    Member since:
    Feb 2015

    Posted 22 Jul 2015 in reply to Daniel Link to this post

    Hi Daniel,

    Thanks for the suggestion, I'm one step closer to my goal.  I actually discovered that workaround as well just before I got your reply, however, I am still struggling with the fact that I will need different Model definitions for all the different use cases of the PersonDTO.  For example, I may feed an array of PersonDTOs to 2 different grids.  One grid will have only the name field be editable and one grid will have, for example, only the addresss field be editable.  How can I achieve that with only one model definition?  I do not want to create different versions of the PersonDTO for every widget I want to feed it to.  I also need to have only one PersonDTO instance represent a particular person and that instance should be used everywhere throughout the client code, so that I don't have to manually copy changes back and forth between instances.

    Thanks!

    Michelle

  5. Daniel
    Admin
    Daniel avatar
    2118 posts

    Posted 23 Jul 2015 Link to this post

    Hello again Michelle,

    I am afraid that a single instance cannot be used with different model definitions. The field definitions are added to the model prototype so the options will be shared between all instances of the same type. The widget will also check the model instance fields definition and not the model definition passed to the schema so passing an inherited type with different definitions is also not an option.
    Possible approaches to use the same instance but make a specific field editable for one grid but not for other, are to use a template column without setting the field or to use readonly editor for the column. 

    Regards,
    Daniel
    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