EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on June 05, 2014, 04:53:28 PM



Title: move node up and down in tree [Solved]
Post by: devnull on June 05, 2014, 04:53:28 PM
How can I drag items up and down the tree ?

My tree looks like this:

Code:
tree
-parent
--item1
--item2
--item3

I would like to be able to select any child and move it up or down the tree, or use a context menu to mode up or down the selected node ?

Code:
tree
-parent
--item3
--item1
--item2


Title: Re: move node up and down in tree
Post by: stworthy on June 06, 2014, 12:12:22 AM
Please extend a new method to achieve this functionality.
Code:
$.extend($.fn.tree.methods,{
move: function(jq, param){
return jq.each(function(){
var t = $(this);
var li = $(param.target).parent();
li = param.dir=='up' ? li.prev() : li.next();
var pnode = li.children('div.tree-node');
if (pnode.length){
var data = t.tree('pop', param.target);
var options = {data:data};
if (param.dir == 'up'){
options['before'] = pnode[0];
} else {
options['after'] = pnode[0];
}
t.tree('insert',options);
}
})
}
})
Find a node and call 'move' method to move a node up or down.
Code:
var node = $('#tt').tree('find','123');
$('#tt').tree('move',{
  target: node.target,
  dir: 'up'  // move up
});


Title: Re: move node up and down in tree [Solved]
Post by: devnull on June 06, 2014, 01:33:25 AM
That's great thank you.

Could this also be somehow used with drag and drop ??

At the moment I have a context menu to move up and down, dragging would be neat, but not essential.

Thanks again.