Syncing children in a DataSource

7 posts, 0 answers
  1. Ian
    Ian avatar
    12 posts
    Member since:
    Sep 2017

    Posted 07 Nov 2017 Link to this post

     If I have a node in a HierarchicalDataSource, and I want to sync changes to it, I assume I should call

    node.parentNode().children.sync()

    When I call this, the resulting data packet contains, as its 'id' property, the id of the parentNode, not of the child. 

    This seems to be due to the fact that kendo.data.Node's _initChildren function indiscriminately applies the parent's identity to the request's data object. 

    Clearly, that makes no sense for update/delete actions, where some other property would make more sense, or the ability to include or not include the parent property. 

    Arguably, the entire path should be available, for situations where a node can exist in multiple places in the tree. 

    I suppose I could overcome this with the data: property being a function, but I think the basic assumption is mistaken.

     

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1812 posts

    Posted 09 Nov 2017 Link to this post

    Hello Ian,

    Would you elaborate in more detail on the widgets you are using? Also please describe the scenario you would like to implement. 

    Have in mind that currently the widgets that are aware of HierarchicalDataSource are TreeView and PanelBar. If you would like to have a widget that supports editing I would suggest using the TreeList and DataSource. 



    Regards,
    Viktor Tachev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Ian
    Ian avatar
    12 posts
    Member since:
    Sep 2017

    Posted 09 Nov 2017 in reply to Viktor Tachev Link to this post

    A Treelist doesn't work for what I am developing because the parents and children are items of different types, with different fields. 

    So a parent might be a region, and its child might be a brand, and that item's child might be a product, and they all have differing properties that don't suit them to being displayed in the same grid.
  4. Ian
    Ian avatar
    12 posts
    Member since:
    Sep 2017

    Posted 10 Nov 2017 Link to this post

    Additionally, when performing a node.parentNode().children.sync() to update a field in a node with children, that sync call either

    1. removes node's own children (never runs _updateChildrenField and simply overwrites the node[childrenFieldName] array, even though node.children is still populated with existing (and possibly new) records, or
    2. replaces the node's node[childrenFieldName] array with the JSON from the server, without processing those values as new models, just applying the array to the node[childrenFieldName

    The work-around I've used is to always call  
    node._updateChildrenField();
    node.children.trigger("change");

    after every "update" sync on a node that has children. 

  5. Ian
    Ian avatar
    12 posts
    Member since:
    Sep 2017

    Posted 10 Nov 2017 in reply to Ian Link to this post

    Additionally,  the Node's _initChildren method binds the change event and bubbles that event upward, which means on "remove" actions, the removed node is added to EVERY PARENT's _destroyed list, the entire way up the hierarchy. 
  6. Ian
    Ian avatar
    12 posts
    Member since:
    Sep 2017

    Posted 10 Nov 2017 Link to this post

    (the fix to the above is to additionally detect when the event.action == "remove" and return before bubbling.
  7. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1812 posts

    Posted 13 Nov 2017 Link to this post

    Hi Ian,

    I am glad that you have the functionality up and running. Thank you for sharing your approach.

    With that said, have in mind that the TreeView and PanelBar components are not intended for CRUD operations. If you would like to use editing and the TreeList is not suitable you can use the Grid component.  



    Regards,
    Viktor Tachev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top