Oras
Oras

Reputation: 1096

Sencha Touch, How to change the tabpanel active item from a view

Today I was trying to set the active item on a tabpanel from a button inside a view and thought of share the code, so its already a solved question. You can see my answer below.

Upvotes: 3

Views: 5324

Answers (1)

(Changed to a community wiki answer to suit SO Q & A format)

The OP wrote:

All you need is to assign an id for the tabpanel like the following code:

Ext.define("appName.view.Main", { extend: 'Ext.tab.Panel', id: 'mainTabPanel',

Then use the following code to retrieve this tabpanel and set the active item

Ext.getCmp('mainTabPanel').setActiveItem(1);

Hope this will help someone

@Dawesi wrote:

just for anyone else looking at this, you can pass the index, the panel id or the panel object itself to set active item

@Proto Bassi wrote:

Instead of Ext.getCmp() you should use Ext.Viewport.down() as this will stop as soon as it finds a match. getCmp will look through all items and that might take longer. And you should use itemId instead of id.

Upvotes: 2

Related Questions