What I have done is an override on the "Ext.tab.Panel" and added a function called: "closeActiveTab". This function doesn't close the panel, but instead does the close on the tab button. Doing this, it will fire all the events like you have clicked on the cross on the button itself.
Code:
Ext.define('Ext.overrides.tab.Panel', {
override: 'Ext.tab.Panel',
/**
* function to close the panel, by executing
* the close on the tab button, rather than the panel
* itself (bug Ext JS 6.0.2/3)
* It closes the active tab.
*/
closeActiveTab: function () {
var tabBar = this.getTabBar();
var activeTab = this.getActiveTab();
var idx = this.items.findIndex('id', activeTab.id);
var button = tabBar.items.getAt(idx);
tabBar.closeTab(button);
}
});
I use it like this:
Code:
tabPanel.add({
extend: 'Ext.form.Panel',
...
listeners: {
scope: me,
beforedestroy: function () {
tabPanel.setActiveTab(0);
},
PatientSaved: function (panel, records, key) {
tabPanel.closeActiveTab();
// do some more
},
closePatientMaintPanel: function (panel) {
tabPanel.closeActiveTab();
}
}
...
});
!!! Important: without the beforedestroy listener on the added tab it doesn't work either. So it should not be forgotten.