PDA

View Full Version : [FIXED-1030] Unable to delete tree node when it hasn't been rendered yet



chh
8 Jun 2010, 1:45 AM
Ext version tested:

Ext 3.2.1

Adapter used:

ext


css used:

only default ext-all.css


Browser versions tested against:

FF3.6.4 (firebug 1.5.4 installed)


Operating System:

WinXP Pro


Description:
When trying to delete the last child of a tree node which hasn't been rendered yet, you get an error saying "this.ctNode is undefined". This is because the parent node is collapsed with no regard to whether it has been rendered or not.

Test Case:



var r = new Ext.tree.TreeNode({
text: 'root',
expanded: true,
leaf: false
});

var n1 = new Ext.tree.TreeNode({
text: 'node1',
expanded: true,
leaf: false
});

var w = new Ext.Window({
layout: 'fit',
title: 'Tree window',
width: 200,
height: 200,
items: [
{
xtype: 'treepanel',
title: 'Tree Panel',
root: r
}]
});

//w.show();

r.appendChild(n1);
r.removeChild(n1);


Steps to reproduce the problem:

Just run the code above in a page which has Ext 3.2.1 loaded. It will give the described error. Try removing the comment from the w.show() line and run it again. The error is gone and a window with a tree panel and a single node 'root' is visible.


Possible fix:
This override fixes the problem but I'm not sure it is the right place to fix it. My changes in red.


Ext.override(Ext.tree.TreeNode, {
// private override
removeChild: function(node, destroy)
{
this.ownerTree.getSelectionModel().unselect(node);
Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
// only update the ui if we're not destroying
if (!destroy)
{
// if it's been rendered remove dom node
if (node.ui.rendered)
{
node.ui.remove();
}
if (this.childNodes.length < 1)
{
if (node.ui.rendered)
{
this.collapse(false, false);
}
} else
{
this.ui.updateExpandIcon();
}
if (!this.firstChild && !this.isHiddenRoot())
{
this.childrenRendered = false;
}
}
return node;
}
});

evant
27 Jun 2010, 9:58 PM
Thanks for the report, it's been corrected in SVN for 3.3.