Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get currently active item`s index number (and not active item`s id) on a card layout on Extjs?

How do I get the currently active item's index number (and not active item's id) on a card layout? The following code will return active item's id:

     Ext.getCmp('my-wizard').getLayout().activeItem.id];

What if I don't want to define an id for my component items and I just want to access active item's index number?

like image 352
Mehdi Fanai Avatar asked Jun 01 '11 21:06

Mehdi Fanai


1 Answers

I couldn't find a built-in quick and easy way, but the following would work:

var wiz = Ext.getCmp('my-wizard');
var activeItem = wiz.getLayout().activeItem;
var activeIndex = wiz.items.indexOf(activeItem);

If this was something that you wanted to do often, you could add it to the CardLayout prototype:

Ext.override(Ext.layout.CardLayout, {
    getActiveIndex: function() {
        return this.container.items.indexOf(this.activeItem);
    }
});

Then you could use it with:

var activeIndex = Ext.getCmp('my-wizard').getLayout().getActiveIndex();
like image 119
Sean Adkinson Avatar answered Oct 16 '22 11:10

Sean Adkinson