PDA

View Full Version : component destroyed when is removed



sofway
11 Feb 2010, 8:11 PM
Hi,
I have a table component that i add to a panel. Then i use panel.remove(table_component), but then i need to assign the table_component again to the panel but it seems that when i remove the table_component it is destroyed.

I dont want to use hide methods, i just want to assign and unassign components to the panel without destroying.

Thanks

dzwillia
11 Feb 2010, 8:57 PM
Hi,

By default, components are destroyed from an Ext.Panel when they are removed. You need to specify 'autoDestroy: false' in the config for the panel when you create it. You can always check out Ext.Panel's documentation (http://www.extjs.com/deploy/dev/docs/?class=Ext.Panel) for more help if you need it.


var myPanel = new Ext.Panel({
...
autoDestroy: false,
...

items: [{
// put the component you don't want destroyed here
}]
});

Animal
12 Feb 2010, 12:56 AM
Hi,
I have a table component that i add to a panel. Then i use panel.remove(table_component), but then i need to assign the table_component again to the panel but it seems that when i remove the table_component it is destroyed.

I dont want to use hide methods, i just want to assign and unassign components to the panel without destroying.

Thanks


Have you read the API docs for Container.remove?

What are the parameters?

sofway
24 Feb 2010, 8:36 PM
Ok i can set the autoDestroy in the container config and i cant set this in the remove event.
But when i set the autoDestroy to false, the component doesnt quit from the container.

I need to quit the component from the container without destroying.

Thanks

dzwillia
24 Feb 2010, 10:03 PM
Works fine for me -- both specifying 'autoDestroy: true' in the panel config as well as calling panel.remove(to_remove, false). If you could copy and paste the code that is causing problems, that'd be helpful.

Here's a quick example which is working as expected:



var to_remove = new Ext.form.TextField({
fieldLabel: 'Remove me',
width: 550,
value: 'Remove me sample text'
});

var to_keep = new Ext.form.TextField({
fieldLabel: 'Keep me',
width: 550,
value: 'Keep me sample text'
});

var panel = new Ext.form.FormPanel({
title: 'Panel Remove Test',
renderTo: Ext.getBody(),
width: 680,
padding: 10,

items: [
to_remove,
to_keep
]
});
panel.remove(to_remove, false);

sofway
25 Feb 2010, 5:57 PM
Works fine for me -- both specifying 'autoDestroy: true' in the panel config as well as calling panel.remove(to_remove, false). If you could copy and paste the code that is causing problems, that'd be helpful.

Here's a quick example which is working as expected:



var to_remove = new Ext.form.TextField({
fieldLabel: 'Remove me',
width: 550,
value: 'Remove me sample text'
});

var to_keep = new Ext.form.TextField({
fieldLabel: 'Keep me',
width: 550,
value: 'Keep me sample text'
});

var panel = new Ext.form.FormPanel({
title: 'Panel Remove Test',
renderTo: Ext.getBody(),
width: 680,
padding: 10,

items: [
to_remove,
to_keep
]
});
panel.remove(to_remove, false);


dzwillia, that works, but then i need to add the textfield again, so..
panel.add(to_remove);
panel.doLayout();

and it doesnt show up :(:(

sofway
26 Feb 2010, 6:43 AM
so ??

dzwillia
26 Feb 2010, 8:21 AM
Sofway,

A couple of things...

1) If you're simply trying to toggle the panel from being shown without destroying it (which sounds like what you are trying to do), you can just use show() and hide() on the contained panel. You haven't provided any code snippets, so I'm having to take some shots in the dark as to what you want to do. Here's the code for showing/hiding a component:



var to_remove = new Ext.Panel({
padding: 10,
html: 'Hide me and then show me'
});

var to_keep = new Ext.Panel({
padding: 10,
html: 'Keep me'
});

var panel = new Ext.Panel({
title: 'Panel Hide Test',
renderTo: Ext.getBody(),
width: 600,
padding: 10,

items: [
to_remove,
to_keep
]
});

(function() {
to_remove.hide();
}).defer(4000);


(function() {
to_remove.show();
}).defer(8000);


2) I try to be as helpful and uplifting as I can on these forums, but it's a little frustrating (and slightly angering) to walk into the office in the morning and see a post at 8:00 p.m. last night with further issues and then another one this morning saying "so?" These are the public forums... if you need a 12-hour turnaround on your forum posts, please consider the premium forums. :)

All the best!

sofway
26 Feb 2010, 8:47 AM
dzwillia, please excuse me if i was disrespectful.
Your help has been great.


I just want to know why i cant then add the component again after is has been removed with the autodestroy false. It seems more elegant to manipulate the components adding and removing than setting the show and hide. Im a amateur in this field and everything you say about is deeply helpful for me.

Thanks and excuse me again.
Your example fits perfect with the situation.