Removing a tab from tabPanel

var tabPanel = Ext.getCmp('tabPanel');
for(var i=1; i<tabPanel.items.length; i++)
{
    tabPanel.items.removeAt(i);
    i--;
}
tabPanel.doLayout();

I am trying to remove all tabs (except the first) from tabPanel. This code does this. I tested it with firebug.
But still, this is not reflected in the user interface. Is doLayout () enough?

+3
source share
2 answers

Instead of calling

tabPanel.items.removeAt(i);

Call

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

Then you tell the container instead of the mixed collection to remove the tab

Another way to do this is

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

This closes the tab by clicking the middle mouse button.

var middleClick = $(document).mousedown(function(e) {
    if(e.which == 2){
              var tabPanel = <%= tabPanel.ClientID %>;    
              var activeTab = tabPanel.getActiveTab();
              if (e.target.textContent == activeTab.title) {
                  var activeTabIndex = tabPanel.items.findIndex('id', activeTab.id);
                  tabPanel.remove(activeTabIndex);
              }
          }
          return true;
    });

Hope this helps! =)

0
source

All Articles