Grid.dataItems() question

8 posts, 2 answers
  1. Keith
    Keith avatar
    7 posts
    Member since:
    Feb 2016

    Posted 03 Jul 2017 Link to this post

    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

  2. Georgi
    Admin
    Georgi avatar
    676 posts

    Posted 04 Jul 2017 Link to this post

    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.
  3. Keith
    Keith avatar
    7 posts
    Member since:
    Feb 2016

    Posted 05 Jul 2017 in reply to Georgi Link to this post

    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

  4. Keith
    Keith avatar
    7 posts
    Member since:
    Feb 2016

    Posted 05 Jul 2017 in reply to Georgi Link to this post

    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

  5. Answer
    Georgi
    Admin
    Georgi avatar
    676 posts

    Posted 10 Jul 2017 Link to this post

    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.
  6. Keith
    Keith avatar
    7 posts
    Member since:
    Feb 2016

    Posted 10 Jul 2017 in reply to Georgi Link to this post

    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

  7. Answer
    Georgi
    Admin
    Georgi avatar
    676 posts

    Posted 12 Jul 2017 Link to this post

    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.
  8. Keith
    Keith avatar
    7 posts
    Member since:
    Feb 2016

    Posted 12 Jul 2017 in reply to Georgi Link to this post

    thanks!

    Keith

Back to Top