View Full Version : Correct way to remove an existing component

1 Dec 2010, 4:53 AM
I use the following code to check if a component exists and if this is true, remove it.

if (typeof (Ext.getCmp('myList')) != 'undefined')
MyNameSpace.myPanel.remove(Ext.getCmp('myList'), true);

The list and the panel are configured:

MyNameSpace.myList= new Ext.List({
fullscreen: true,
id: 'myList',
itemTpl: '<strong>{name}</strong>',
singleSelect: true,
grouped: true,
store: (MyNameSpace.Main.movieId === 1) ? MyNameSpace.cinemasStoreShort1 : MyNameSpace.cinemasStoreShort2,
indexBar: true

DemoEthniki.movieDetailsPanel = new Ext.Panel({
id: 'toolbartxt',

But this doesn't seem to work well, because after sometime the component is not removed and seems to be over another component. Any ideas? It is obvious that something I do wrong but what exactly? Thanks in advance

1 Dec 2010, 4:55 AM
doLayout to lay out a Container.

doComponentLayout is for Components with internal structure which may need to be updated.

1 Dec 2010, 5:25 AM
Firstly, I'd like to thank you Animal for your immediate answer. Secondly, when I use remove in the way I wrote in the code snippet above, I'm getting the following warning:
Attempted to remove a component that does not exist. Ext.Container: remove takes an argument of the component to remove. cmp.remove() is incorrect usage.. What is the correct way to use this function?

1 Dec 2010, 6:43 AM
How about


1 Dec 2010, 8:29 AM
@tomalex0 : What you propose me to do, doesn't work in the way you (and I) expected :( I believe that there is something is wrong with the following check:

if (typeof (Ext.getCmp('myList')) != 'undefined')

Thanks anyway for your time. I'll investigate the issue and I will give you feedback

1 Dec 2010, 8:41 PM
Did you tried


Are you getting any object?

Also in the code mentioned above, you have not mentioned list as item of panel.

2 Dec 2010, 12:30 AM
No I didn't try logging... That's true. The list is added dynamically in the event handler of a button:

var cinemaHandler = function ()