PDA

View Full Version : Calling remove with autoDestroy:false, does not remove the component



brookd
17 Sep 2010, 10:29 AM
I am not sure if this is a bug or not. When calling remove on a component with autoDestroy:false, the component does not get removed.

I'm using 3.2.1...



// simply panel
mypanel = new Ext.Panel({
id:'mypanel',
width:400,
height:300,
title:'Test',
renderTo:Ext.getBody(),
items:[{
html:'your mamas so fat',
id:'yourmama'
}]
})


And then I call remove



// does not work, component is not removed
Ext.getCmp('mypanel').remove('yourmama',false);

// works, component is removed
Ext.getCmp('mypanel').remove('yourmama',true);


Am I missing something trivial here?

Note, while debugging this, the child component IS removed from the containers items collection, but the display is not updated.

teamhonda81
17 Sep 2010, 11:32 AM
brookd,

The problem is that Ext.getCmp returns an Ext.Component, not an Ext.Element. If you look at the documentation, I don't think there is a remove method for Ext.Component. So instead, I would just do this:


Ext.get('yourmama').remove();

Animal
17 Sep 2010, 11:37 AM
The DOM does indeed not get removed if you do not destroy.

You need this plugin to remove but preserve: http://www.sencha.com/forum/showthread.php?105909-ContainerClear.-Plugin-to-cause-Container.remove-to-remove-removed-Components

Animal
17 Sep 2010, 11:38 AM
brookd,

The problem is that Ext.getCmp returns an Ext.Component, not an Ext.Element. If you look at the documentation, I don't think there is a remove method for Ext.Component. So instead, I would just do this:


Ext.get('yourmama').remove();

NO.

teamhonda81
17 Sep 2010, 11:46 AM
NO.

I read the docs wrong, Animal is right. Now I know how to correctly do this. Thanks for the link Animal.

brookd
17 Sep 2010, 1:21 PM
Thanks Animal. So it looks like with your plugin the DOM would still exist. What I was trying to acheive was the ability to remove and then re-insert back into the DOM without having to do any of the other re-initialization of the component (a dataview..).

I did want to remove it from the DOM though, because I am trying to keep the number of DOM elements down.

So, would I better off just destroying and re-creating as needed then?

Animal
17 Sep 2010, 1:58 PM
That's what this does, you remove it and it gets stashed in a hidden container for you to use later. More efficient than recreating I'd say.

brookd
17 Sep 2010, 2:18 PM
I guess I am just concerned about bloating the DOM with a bunch of hidden elements....

Animal
17 Sep 2010, 10:40 PM
Well you're not destroying the Components, so their DOM is going to be there. Somewhere.