官术网_书友最值得收藏!

Stacking items with an accordion layout

Countless applications use a layout where multiple panels are positioned in an expandable accordion style, such that only one panel can be open at any given time. This recipe is a sample that tries to borrow the look of popular email applications to explain how to configure and use an accordion layout.

Stacking items with an accordion layout

How to do it...

  1. Create the Mail panel:
    panel1=new Ext.Panel({
    title: 'Mail',
    items: [{
    xtype: 'treepanel',
    id: 'inbox-tree',
    autoScroll: true,
    animate: true,
    enableDD: true,
    containerScroll: true,
    border: false,
    dataUrl: 'mail-folders.php',
    root: {
    nodeType: 'async',
    text: 'MailBox',
    draggable: false,
    id: 'mailbox'
    }
    }]
    });
    
  2. Create the Calendar panel:
    panel2=new Ext.Panel({
    title: 'Calendar',
    bodyStyle: 'padding:10px',
    items: [{ xtype: 'datepicker',
    style: 'border:0'
    }]
    });
    
  3. Create the Contacts panel:
    panel3=new Ext.Panel({
    title: 'Contacts',
    bodyStyle: 'padding:10px',
    items: [{ xtype: 'fieldset',
    title: 'Current View',
    autoHeight: true,
    bodyStyle: 'padding:3px',
    items: [
    { xtype: 'radio', boxLabel: 'Address Cards',
    hideLabel: true, name: 'contacts-view',
    checked: true },
    { xtype: 'radio', boxLabel: 'Phone List',
    hideLabel: true, name: 'contacts-view' },
    { xtype: 'radio', boxLabel: 'By Category',
    hideLabel: true, name: 'contacts-view' },
    { xtype: 'radio', boxLabel: 'By Location',
    hideLabel: true, name: 'contacts-view'}]
    }]
    });
    
  4. Now position the panels in a container and expand the tree's root node.
    var container=new Ext.Panel({
    title: 'Accordion Layout',
    width: 200,
    height: 350,
    applyTo: 'accordion-panel',
    // Displays one item at a time in a stacked layout.
    layout: 'accordion',
    items: [panel1, panel2, panel3]
    });
    // Expand the root node of the tree.
    Ext.getCmp('inbox-tree').getRootNode().expand();
    

How it works...

The trick to the stacked panels resides in specifying an AccordionLayout for the layout configuration option of the container.

There's more...

Together with CardLayout, AccordionLayout, is a popular layout choice when UI real estate is at a premium. This is because it allows you to keep visible the contents of just one panel at a time.

See also...

  • The next recipe, Wizard-style UI using a card layout, explains how to create a wizard to lead the user through multiple steps
主站蜘蛛池模板: 长葛市| 甘泉县| 鹰潭市| 虎林市| 姚安县| 遵化市| 潮州市| 尼木县| 万宁市| 绿春县| 岳普湖县| 海淀区| 林周县| 普兰县| 凤庆县| 漳浦县| 马龙县| 大渡口区| 新巴尔虎右旗| 得荣县| 桐城市| 白玉县| 罗城| 巩留县| 衡水市| 泰州市| 珠海市| 彭州市| 博兴县| 远安县| 泸定县| 光山县| 芜湖县| 柳林县| 登封市| 和平区| 茌平县| 游戏| 昌乐县| 甘南县| 甘德县|