I populate my grid with objects of a specific class, but when i get them via Grid.dataItems(), they are no longer that specific class but plain objects. is there a way to not have Kendo Grid lose their Initial Class type? Or better yet, have the Grid just use the original objects i give? I want to be able to call the specific class's methods from the individual dataItems, but i can't because of this.
Thanks
Keith
9 Answers, 1 is accepted
In case your models are JavaScript objects, you can execute their methods when you get them through the dataItems function of the grid. Please refer to the following dojo:
However if you retrieve the data from a remote server, since the data is serialized on the server before it's sent to the client, it is possible to deserialize only properties.
With that said, would you elaborate a bit more on the scenario you would like to implement? What are the requirements and what should be the expected behavior?
Regards,
Georgi
Progress Telerik

Hi Georgi,
you are correct, that works and is how i was using it. what doesn't work is using JS 6 classes
please see this example: http://dojo.telerik.com/@kdragon/AFoGOT/2
thanks
Keith

Hi Georgi,
you are correct, that works and is how i was using it. what doesn't work is when i try to use JS 6 classes
see this example: http://dojo.telerik.com/@kdragon/AFoGOT/2
thanks
Keith
This happens because when an item is added to the data source it is copied. The logic for copying the object is to iterate through the keys of the properties and then copy their value. When defining a method using ecmascript 6 syntax, the identifier of the method is not an object key of the created instance of the class and it is not copied to the data source object.
However I modified your example in order to expose the methods, you can even use private properties with the following workaround:
With that said, would you elaborate a bit more on the scenario you would like to implement? What are the requirements and what should be the expected behavior?
Regards,
Georgi
Progress Telerik

cool, datasource.data() seems to work fine. any downside to this? do grid edits propagate back to these objects?
not much to the scenario, beyond the fact i was looking for a way to populate with js6 class objects and call their methods. i'm trying to use js6 classes and other features where i can
sorry about double replying on this thread, i was getting an error when i replied, so i replied a second time
thanks!
Keith
The difference between grid.dataItems and grid.dataSource.data() is that the first returns the items from the current view (e.g. current page) and the second returns the whole data inside the data source. In this case since the data is hard coded array, both return the same collection.
And yes, when you edit an item the changes are applied to the objects returned from dataitems method.
Regards,
Georgi
Progress Telerik

thanks!
Keith

Hello Mikkel,
The dataItems method of the grid is internal for the widget and it is not part of the API. Nevertheless, internally the dataItems method simply calls the view method of the dataSource. Both view and data methods are documented in the API docs of the dataSource:
I hope this helps.
Regards,
Georgi
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.