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

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

3 Answers 222 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Michelle
Top achievements
Rank 1
Michelle asked on 20 Jul 2015, 07:37 PM

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!

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Jul 2015, 03:03 PM
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!
 
0
Michelle
Top achievements
Rank 1
answered on 22 Jul 2015, 07:19 PM

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

0
Daniel
Telerik team
answered on 23 Jul 2015, 03:33 PM
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!
 
Tags
Data Source
Asked by
Michelle
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Michelle
Top achievements
Rank 1
Share this question
or