EasyUI Forum
May 03, 2024, 10:32:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: move node up and down in tree [Solved]  (Read 5662 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« 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
« Last Edit: June 06, 2014, 01:31:34 AM by devnull » Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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
});
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #2 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.
Logged

-- Licensed User --
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!