EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: leela on July 08, 2014, 02:40:51 PM



Title: The Sequence of the Child Nodes in Tree
Post by: leela on July 08, 2014, 02:40:51 PM
Hi,

 I need to identify the sequence of the child nodes of a given node.
 Lets say I have a tree, with drag and drop enabled.
 When the user drags and drops a node with in same parent, and changes its position.
 how do I save that sequence change in the node, under that parent.

 Any response is greatly appreciated.

Thanks,
Leela.
 


Title: Re: The Sequence of the Child Nodes in Tree
Post by: stworthy on July 09, 2014, 01:43:06 AM
After drag and drop a node, the 'onDrop' event fires, in which you can save the node sequence to the database.
Code:
$('#tt').tree({
onDrop: function(target, source, point){
//the 'point' indicates the drop operation, posible values are: 'append','top' or 'bottom'
}
})


Title: Re: The Sequence of the Child Nodes in Tree
Post by: leela on July 09, 2014, 07:52:03 AM
How can I calculate the order and update it for all the elements in the node, based on the re-ordering due to drag and drop.
Is there an attribute for a node, that represents its position in the tree and under its parent?


Title: Re: The Sequence of the Child Nodes in Tree
Post by: stworthy on July 09, 2014, 09:12:40 AM
You don't need to calculate the order for the nodes, the tree plugin has done all for you. Call 'getData' method to get a parent node's data, all the children nodes are in their order.
Code:
var t = $('#tt')
var s = t.tree('getSelected');
$.map(t.tree('getData',s.target).children, function(node){
console.log(node.text)
})