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

Syncing children in a DataSource

6 Answers 317 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 08 Nov 2017, 01:01 AM

 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.

 

6 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 09 Nov 2017, 03:22 PM
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.
0
Ian
Top achievements
Rank 1
answered on 10 Nov 2017, 04:05 AM
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.
0
Ian
Top achievements
Rank 1
answered on 10 Nov 2017, 11:42 PM

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. 

0
Ian
Top achievements
Rank 1
answered on 11 Nov 2017, 04:03 AM
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. 
0
Ian
Top achievements
Rank 1
answered on 11 Nov 2017, 04:03 AM
(the fix to the above is to additionally detect when the event.action == "remove" and return before bubbling.
0
Viktor Tachev
Telerik team
answered on 13 Nov 2017, 11:52 AM
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.
Tags
Hierarchical Data Source
Asked by
Ian
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Ian
Top achievements
Rank 1
Share this question
or