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

Grid.dataItems() question

9 Answers 1008 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 03 Jul 2017, 09:05 PM

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

Sort by
0
Georgi
Telerik team
answered on 04 Jul 2017, 12:36 PM
Hi Keith,

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
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
Keith
Top achievements
Rank 1
answered on 05 Jul 2017, 03:19 PM

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

0
Keith
Top achievements
Rank 1
answered on 05 Jul 2017, 03:20 PM

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

0
Accepted
Georgi
Telerik team
answered on 10 Jul 2017, 06:50 AM
Hello 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
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
Keith
Top achievements
Rank 1
answered on 10 Jul 2017, 03:18 PM

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

0
Accepted
Georgi
Telerik team
answered on 12 Jul 2017, 12:09 PM
Hi 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
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
Keith
Top achievements
Rank 1
answered on 12 Jul 2017, 03:10 PM

thanks!

Keith

0
Mikkel
Top achievements
Rank 1
Veteran
answered on 03 Dec 2020, 08:53 AM
Howcome grid.dataItems is not in the documentation for the grid (nor for the dataSource)? The difference that you describe here between grid.dataItems and grid.dataSource.data() is very important.
0
Georgi
Telerik team
answered on 04 Dec 2020, 03:49 PM

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/.

Tags
Grid
Asked by
Keith
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Keith
Top achievements
Rank 1
Mikkel
Top achievements
Rank 1
Veteran
Share this question
or