Reputation: 562
The listener I set up with doesn't seem to trigger. Here is my code:
new Ext.TabPanel({
id:'content-tab-panel',
renderTo: 'trx_tabs_ext',
activeTab: 0,
minTabWidth: 150,
tabWidth:180,
enableTabScroll: true,
autoScroll: true,
resizeTabs:true,
defaults: {
autoScroll:true
},
items: [{
title: 'No Active Chat',
id: 'no_chat',
closable: true,
autoScroll: false,
margins: '0 0 0 0',
html: "<div id=\"chat_window_viewer\" style=\"width:900px;height:440px;text-align:left; \"> </div>"
}],
width: '100%',
height: '400px',
listeners: {
tabchange: function(tabPanel, newTab, oldTab, index)
{
console.log('change tab');
},
beforeadd : function (tabpane, component, index) {
console.log('Adding new tab');
},
beforeclose: function(element) {
console.log('closing');
}
}
});
The beforeadd an tabchange triggers and do so by writing a log at the console. But, the beforeclose does not.
I also tried putting it inside the item of the Tabpanel, does not work either.
What is the correct way to adding a close event in the TabPanel?
Upvotes: 1
Views: 7191
Reputation: 2139
Since Extjs 2.3.0, tabpanel
s have a beforeclose
event:
beforeremove( this, component, eOpts )
Fires before any
Ext.Component
is removed from the container. A handler can return false to cancel the remove.Available since: 2.3.0
Parameters
- this :
Ext.container.Container
- component :
Ext.Component
The component being removed- eOpts :
Object
The options object passed toExt.util.Observable.addListener
.
so just add a listener in your tabpanel
:
listeners: {
beforeremove: function (panel, item, eOpts) {
console.log(item); // the tab to be removed
}
. . . .
}
Upvotes: 0
Reputation: 2270
Which version of library you are using? Note that beforclose event available since 2.3.0.
It works for me when i listening event for item, not for whole panel
new Ext.TabPanel({
id:'content-tab-panel',
renderTo: 'trx_tabs_ext',
activeTab: 0,
minTabWidth: 150,
tabWidth:180,
enableTabScroll: true,
autoScroll: true,
resizeTabs:true,
defaults: {
autoScroll:true
},
items: [{
title: 'No Active Chat',
id: 'no_chat',
closable: true,
autoScroll: false,
margins: '0 0 0 0',
html: "<div id=\"chat_window_viewer\" style=\"width:900px;height:440px;text-align:left; \"> </div>",
listeners:{
'beforeclose': function(){console.log('closed')}
}
}],
width: '100%',
height: '400px',
listeners: {
tabchange: function(tabPanel, newTab, oldTab, index)
{
console.log('change tab');
},
beforeadd : function (tabpane, component, index) {
console.log('Adding new tab');
}
}
});
Upvotes: 0
Reputation: 1951
To get items close event, add listener to that item.
Fiddle here: https://fiddle.sencha.com/#fiddle/59f
Upvotes: 1