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

  • Ext JS 3.0 Cookbook
  • Jorge Ramon
  • 324字
  • 2021-04-01 13:43:47

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
主站蜘蛛池模板: 敦煌市| 台东县| 舞钢市| 郎溪县| 呼图壁县| 潞西市| 平邑县| 遵化市| 麻城市| 长武县| 崇州市| 健康| 克什克腾旗| 同仁县| 松滋市| 庆元县| 浦北县| 邻水| 合江县| 宁明县| 贵德县| 云梦县| 庄河市| 五台县| 丹寨县| 西贡区| 玉溪市| 台州市| 乌恰县| 双辽市| 密云县| 六盘水市| 宁波市| 抚宁县| 吉安市| 屏边| 樟树市| 大理市| 醴陵市| 天镇县| 仁寿县|