tags:

views:

68

answers:

3

Hello All,

I have a tree where users can drag and drop branches. Now this works all well and good, but i need to be able to move a branch programmatically. I need to simulate a cut and paste (i will have the user using buttons instead of Cntrl X and V) Anyone have an idea of where i should start? Any help would be greatly appreciated.

Thanks

A: 

Hello

I have never played with that method so I can't really give you a full solutin, but the TreePanel class has a movenode method with the following arguments... Tree tree, Node node, Node oldParent, Node newParent, Number index

There are also events tied to this method. Hope this helps.

EDIT - I read the API too quick, those are events. I think the only way you can manually do this is by using the appendChild and removeChild methods.

SBUJOLD
I'm looking in the API, and I can only find a moveNode event, I don't see a method.
Limey
Yes you're right I'm sorry. You're gonna need to use the appendChild and removeChild methods.
SBUJOLD
A: 

Ok, i found the solution and it ended up being really, REALLY simple:

var child = tree.getSelectionModel().getSelectedNodes();
var parent = tree.getNodeById('ABC123');
parent.appendChild(child);

it will even automagically remove the node from its original spot and it even moves any children of the node moved.

Note that this will only work on one node at the moment (even though it is using selectedNodes) i will post something more substantial later.

Limey
A: 

Here is a cut and paste that will work for multiple nodes at one time. This version will also hide any nodes that have been "cut" and won't show them again till they get pasted. during the paste it will only use the first node selected, all others will just be ignored.

var Children = new Array();

function CutChildren(){
    Children = tree.getSelectionModel().getSelectedNodes();
    var limit = Children.length;
    for (count =0; count < limit; count++){
        Children[count].getUI().hide();
    }

}

function PasteChildren(){
    var selected = new Array();
    selected = tree.getSelectionModel().getSelectedNodes();
    var limit = Children.length;
    for (count =0; count < limit; count++){
        selected[0].appendChild(Children[count]);
        Children[count].getUI().show();
        if (count > 100){
        break;}
    }

}
Limey