12

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?

Patricia
  • 7,752
  • 4
  • 37
  • 70
Mehdi Fanai
  • 4,021
  • 13
  • 50
  • 75

1 Answers1

24

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();
Sean Adkinson
  • 8,425
  • 3
  • 45
  • 64
  • Quick note: I didn't notice your question was tagged with `extjs4`, and my answer applies to ExtJS 3, so it may or may not work with ExtJS 4. – Sean Adkinson Jun 01 '11 at 21:35
  • Thanks for your very practical and working answer.sorry that stackoverflow doesn`t let me vote up... – Mehdi Fanai Jun 05 '11 at 01:55