PDA

View Full Version : [FIXED-476][3.1r5800+] TreeNode insertBefore Broken for new nodes



vtswingkid
21 Jan 2010, 7:40 PM
I haven't tested this for moving existing nodes.
But for new nodes inserting ends up appending the way it is.
I think if it already exists it would have a parentNode.
If it were new it wouldn't.


Recommened Fix in red:



insertBefore : function(node, refNode){
var newNode, exists;
if(!node.render){
node = this.getLoader().createNode(node);
}else{
//exists = !node.parentNode;
exists = Ext.isObject(node.parentNode);
}
newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode);
if(newNode && refNode){
this.afterAdd(newNode, exists);
}
this.ui.updateExpandIcon();
return newNode;
}

evant
21 Jan 2010, 10:12 PM
Can you post a test case?



Ext.onReady(function(){
var tp = new Ext.tree.TreePanel({
width: 400,
height: 400,
renderTo: document.body,
animate: false,
root: {
nodeType: 'node',
text: 'Root'
}
});
var root = tp.getRootNode();
for(var i = 0; i < 5; ++i){
root.appendChild({
text: 'Node ' + i
});
}
root.expand();
root.insertBefore({
text: 'Foo'
}, root.childNodes[2]);
});

vtswingkid
22 Jan 2010, 12:30 AM
Simply creating the treenode before inserting it reproduces the insert problem. See the modified example below.


Ext.onReady(function(){
var tp = new Ext.tree.TreePanel({
width: 400,
height: 400,
renderTo: document.body,
animate: false,
root: {
nodeType: 'node',
text: 'Root'
}
});
var root = tp.getRootNode();
for(var i = 0; i < 5; ++i){
root.appendChild({
text: 'Node ' + i
});
}
root.expand();
root.insertBefore(new Ext.tree.TreeNode({
text: 'Foo'
}), root.childNodes[2]);
});

vtswingkid
22 Jan 2010, 10:29 AM
Were you able to replicate it based on my example?

evant
24 Jan 2010, 4:23 PM
I can see the issue now, I'm looking into it.

stefan.lotties
10 Mar 2010, 5:16 AM
Is there already a (community) solution for this problem?

evant
10 Mar 2010, 5:26 AM
The change that caused this problem was reverted, it will be out with 3.2.