Removing a tab from tabPanel

Shashwat picture Shashwat · Apr 27, 2012 · Viewed 7.2k times · Source
var tabPanel = Ext.getCmp('tabPanel');
for(var i=1; i<tabPanel.items.length; i++)
{
    tabPanel.items.removeAt(i);
    i--;
}
tabPanel.doLayout();

I'm trying to remove all the tabs (except the first one) from the tabPanel. This code is doing that. I checked it using firebug.
But still, it is not reflecting in the UI. Isn't doLayout() enough?

Answer

Juan Mendes picture Juan Mendes · Apr 27, 2012

Instead of calling

tabPanel.items.removeAt(i);

Call

tabPanel.remove(tabPanel.items.getAt(i));

Then you're telling the container instead of the mixed collection to remove the tab

Another way to do it is

tabPanel.removeChildEls(function(tab){
  return tab != tabPanel.items.first();
});