PDA

View Full Version : Tree no item delete



noso
24 Aug 2007, 7:55 AM
Hi,

I'm using 2 trees (like the two-trees example from EXT). But what I want to do is this:
When I drag one element from one to the other tree I want it to be added to the second tree (no special things there) but it still has to be present in the first. So you could add/drag more than one time the same element from the first to the second tree.

I can't figure it out how to fix this problem :-?
Any suggestions?
Thanks in advance!

para
24 Aug 2007, 8:18 AM
Easy. This was the first thing I tackled in Ext. However, it took me a few weeks to perfect the function :)


tree.on('nodedrop', function(e){
if(e.dropNode.getOwnerTree() !== e.target.getOwnerTree()) {
e.dropNode = e.dropNode.clone();
}
});


Ext.override(Ext.tree.TreeNode, {
clone: function() {
//forces creation of a new id by removing the original.
var atts = this.attributes;
atts.id = undefined;
var newNode = new Ext.tree.TreeNode(Ext.apply({}, atts));
newNode.text = this.text;

for(var i=0; i<this.childNodes.length; i++){
newNode.appendChild(this.childNodes[i].clone());
}
return newNode;
}
});


This may not be the cleanest/most efficient method, but it's pretty close.
Works flawlessly for me. (Although I did strip out a few things that are specific to my application, so there may be an error or two)

noso
25 Aug 2007, 2:58 AM
Big Thanks! \:D/=D>;) I will test this soon!