1
votes

I have a extjs button "Order" with menu items 'orderInsuranceMenu' for the button. I need to hide the menu items depeniding on some condition. How can i achive it

orderInsuranceMenu = {
    id: 'menu-order-insurance'
    ,items: [
          { 
            id:'btnMenu1',
            text: 'Test Buton1',
            iconCls: 'icon-cls',
            listeners: {
                click: function(b,e){  
                   //some code goes here
                }
            }
        }
        ,{
            id:'btnMenu2',
            text: 'Test Buton2',
            iconCls: 'icon-first-title',
            listeners: {
                click: function(b,e){  
                    //Some code here
                }
            }
        }

    ]
};



Order = new Ext.Button({
    text: 'Order '
    , iconCls: 'icon-go'
    , disabled: true
    , menu: orderInsuranceMenu
    , handler: function() {
    }

});

I have tried this code but it doesnt work:

Ext.getCmp('btnMenu2').hide();

3

3 Answers

3
votes

You can achieve this with the method setDisabled for the button. I.e:

Ext.getCmp('btnMenu2').setDisabled(true);

If you want to apply this for all items in your menu you can do this:

Ext.getCmp('menu-order-insurance').items.each(function(item) {
    if (item.isXType('button')) {
        item.setDisabled(true); // your condition here
    }
});
2
votes

Soloution:

In Extjs 2.2 there is no method to show or hide menu item by using isVisible So after lot of digging and checking in firebug the final soloution I found was to hide or show the specific item as shown below

extManager.orderInsuranceMenu.items.items[1].hide();
orderInsuranceMenu.items.items[1].show();
1
votes

You can use the setVisible method available in 2.2, in menu items. http://i.stack.imgur.com/kdw7f.png

If for some reason that does not work, I would resort to removing the item from the menu, and then adding it back into the menu when it is needed.