PDA

View Full Version : Basic question: best pratice to add Listeners to tabs?



dante
24 Aug 2007, 4:42 AM
I have a page containing a BorderLayout containing ContentPanels and also a NestedLayoutPanel. The latter one has tabs and I would like to have an ajax action executed automatically when a tab is activated. This already works using the following code (example):



mainLayout.getRegion('east').getPanel('east-div2').getLayout().getRegion('center').getPanel('report_periods').addListener('activate', function(){alert('test');});


However, I wonder where to put those Listener definitions? Or is it possible to define a Listener using the constructor of a ContentPanel?

So what's best practice in defining Listeners which don't have to be set up dynamically?

BernardChhun
24 Aug 2007, 8:57 AM
If you don't plan on using the listener function anywhere else, I'd keep it in the addListener() sentence.

Skeleton
24 Aug 2007, 9:54 AM
Do you mean this:


var centerRegion = mainLayout.getRegion('east').getPanel('east-div2').getLayout().getRegion('center');

// Fires when a panel is activated.
centerRegion.on('panelactivated', function(region, panel) {

// Here, you can use the incoming region and panel objects accordingly

}, this);

For more info, look here (http://extjs.com/deploy/ext/docs/output/Ext.LayoutRegion.html#events).