Book Image

Learning Ext JS_Fourth Edition

Book Image

Learning Ext JS_Fourth Edition

Overview of this book

Table of Contents (22 chapters)
Learning Ext JS Fourth Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding menus


There are times when we need to create a menu (or menus) to allow the user to choose from the available options. We can achieve this by setting the menu property of the buttons. This will create a floating menu for the selected button, and it will be shown when the user clicks on the button.

Let's create a button that contains a menu with options. For the following example, we need to create an HTML page, import the Ext JS library, and listen for the DOM ready event. Inside the callback, we should modify the code that creates our button, as shown here:

  var myButton = Ext.create('Ext.button.Button',{
    text:'Add payment method...',
    iconCls:'addicon-32',
    iconAlign:'left',
    scale:'large',
    renderTo:'normalbuttons',
    menu:[
      {text:'Master Card'},
      {text:'Visa'},
      {text:'PayPal'},
      {text:'Other...'}
    ]
  });

As we can see in the previous code, the menu property receives an array of objects. This array will be used to create an instance of...