-
3 Jun 2007 7:40 PM #11
Ok -- thanks that was one thing.
The second thing that needed changing is the function needs to be applied to the other tree
below is a trick to prvent duplicating nodes dragged from inside the tree. This allows user sorting but prevents making additional copiesCode:myfavreport.on('beforenodedrop', function(e){ var n = e.dropNode; // the node that was dropped var copy = new Ext.tree.TreeNode( // copy it Ext.apply({}, n.attributes) ); e.dropNode = copy; // assign the copy as the new dropNode });
Code:myfavreport.on('beforenodedrop', function(e){ var n = e.dropNode; // the node that was dropped if (e.source.el !=this.el) { var copy = new Ext.tree.TreeNode( // copy it Ext.apply({}, n.attributes) ); e.dropNode = copy; // assign the copy as the new dropNode } });Last edited by mhubert; 3 Jun 2007 at 8:11 PM. Reason: improvment I wanted to share w/ the community
-
26 Sep 2007 8:11 AM #12
while copying a node, the node is copied with the same Node ids. Which later leads o problems. Is there a way to change the node ids while creating the copy?
I had this method implemented. but for some reason, the ids are not changed. The append string is passed as "".
Code:function changeNodeIds(node, appendStr) { var chldNodes; alert(appendStr); alert(node.id); if (node.id.length == 0) { chldNodes = node.attributes.children; } else { chldNodes = node.children; } var leafCount = 0; var compCount = 0; if (chldNodes != null) { for (var i=0;i<chldNodes.length;i++) { var chldNode = chldNodes[i]; if (chldNode.leaf) { leafCount++; chldNode.id=appendStr+alphabets.substring(leafCount-1,leafCount); //alert("Leaf Node - "+chldNode.id); } else { compCount++; if (appendStr.length == 1) { chldNode.id=appendStr+(compCount); //alert("Node Id - "+appendStr+(compCount)); } else { chldNode.id=appendStr+"."+(compCount); //alert("Node Id - "+appendStr+"."+(compCount)); } changeNodeIds(chldNode, chldNode.id); } } } }
-
26 Sep 2007 9:20 AM #13
This works for me...
I add a clone() function to Ext.tree.TreeNode
Then I use:Code:Ext.override(Ext.tree.TreeNode, { clone: function() { var atts = this.attributes; atts.id = Ext.id(null, "ynode-"); var clone = new Ext.tree.TreeNode(Ext.apply({}, atts)); clone.text = this.text; for(var i=0; i<this.childNodes.length; i++){ clone.appendChild(this.childNodes[i].clone()); } return clone; } });
Code:tree.on('beforenodedrop', function(e){ if(e.rawEvent.ctrlKey) { // or whatever criteria you want to make for doing a copy instead of a move e.dropNode = e.dropNode.clone(); } });
-
7 Jan 2008 2:39 PM #14
Thanks, but this copy work partialy...
When you copy a non-opening folder, you can't open the copy
Example here : http://www.chassemy.org/sesamath/tree/two-trees.html
nb: To prevent duplicating nodes dragged from inside the tree I have writed this :
Anyone can help me please ?Code:tree2.on('beforenodedrop', function(e){ if(e.source.tree.el != e.target.ownerTree.el) { e.dropNode = e.dropNode.clone(); } });Last edited by broutard; 7 Jan 2008 at 3:58 PM. Reason: adding example
-
8 Jan 2008 6:19 AM #15
That is because the function was made to work with TreeNode, not AsyncTreeNode.
Here's a better version:
I'm sure there's a more efficient way to do this though.Code:Ext.override(Ext.tree.TreeNode, { clone: function() { var atts = this.attributes; atts.id = Ext.id(null, "ynode-"); if(this.childrenRendered || this.loaded || !this.attributes.children) { var clone = new Ext.tree.TreeNode(Ext.apply({}, atts)); } else { var newAtts = Ext.apply({}, atts); newAtts.children = this.cloneUnrenderedChildren(); var clone = new Ext.tree.AsyncTreeNode(newAtts); } newNode.text = this.text; clone.text = this.text; for(var i=0; i<this.childNodes.length; i++){ clone.appendChild(this.childNodes[i].clone()); } return clone; }, cloneUnrenderedChildren: function() { unrenderedClone = function(n) { n.id = undefined; if(n.children) { for(var j=0; j<n.children.length; j++) { n.children[j] = unrenderedClone(n.children[j]); } } return n; }; var c = []; for(var i=0; i<this.attributes.children.length; i++) { c[i] = Ext.apply({}, this.attributes.children[i]); c[i] = unrenderedClone(c[i]); } return c; }, });
-
22 May 2009 10:57 AM #16
-
24 Apr 2012 5:22 AM #17
Complete solution:
Code:Ext.override(Ext.tree.TreeNode, { clone: function() { var atts = this.attributes; if(this.childrenRendered || this.loaded || !this.attributes.children) { var clone = new Ext.tree.TreeNode(Ext.apply({}, atts)); } else { var newAtts = Ext.apply({}, atts); newAtts.children = this.cloneUnrenderedChildren(); var clone = new Ext.tree.AsyncTreeNode(newAtts); } clone.text = this.text; for(var i=0; i<this.childNodes.length; i++){ clone.appendChild(this.childNodes[i].clone()); } return clone; }, cloneUnrenderedChildren: function() { unrenderedClone = function(n) { //n.id = undefined; if(n.children) { for(var j=0; j<n.children.length; j++) { n.children[j] = unrenderedClone(n.children[j]); } } return n; }; var c = []; for(var i=0; i<this.attributes.children.length; i++) { c[i] = Ext.apply({}, this.attributes.children[i]); c[i] = unrenderedClone(c[i]); } return c; } }); Ext.override(Ext.tree.TreeNode, { clone: function() { var atts = this.attributes; if(this.childrenRendered || this.loaded || !this.attributes.children) { var clone = new Ext.tree.TreeNode(Ext.apply({}, atts)); } else { var newAtts = Ext.apply({}, atts); newAtts.children = this.cloneUnrenderedChildren(); var clone = new Ext.tree.AsyncTreeNode(newAtts); } clone.text = this.text; for(var i=0; i<this.childNodes.length; i++){ clone.appendChild(this.childNodes[i].clone()); } return clone; }, cloneUnrenderedChildren: function() { unrenderedClone = function(n) { //n.id = undefined; if(n.children) { for(var j=0; j<n.children.length; j++) { n.children[j] = unrenderedClone(n.children[j]); } } return n; }; var c = []; for(var i=0; i<this.attributes.children.length; i++) { c[i] = Ext.apply({}, this.attributes.children[i]); c[i] = unrenderedClone(c[i]); } return c; } }); ================================================================= 'beforenodedrop': function(e) { if(e.source.tree == e.target.ownerTree) { return true; } var n = e.dropNode; // the node that was dropped var existNode = e.target.ownerTree.getNodeById(n.id); if(e.source.tree.el != e.target.ownerTree.el&&existNode==undefined) { e.dropNode = n.clone(); // assign the copy as the new dropNode } else { return false; } }


Reply With Quote

