简体   繁体   English

Extjs手风琴动态关闭所有面板

[英]Extjs accordion close all panel dynamically

I am using Extjs 5.0.0 我正在使用Extjs 5.0.0

I have an accordion with a number of panels. 我有一个带有许多面板的手风琴。 Here my requirement is to expand and collapse panel by clicking on the title. 这里我的要求是通过单击标题来展开和折叠面板。

On the first click it expanded, that's fine. 在第一次点击它扩展,这没关系。 while again clicking on the same title i want to collapse all the panels. 再次点击相同的标题我想折叠所有面板。 Here its opening the very next panel. 在这里打开下一个面板。

I just tried by expanding a hidden panel. 我只是尝试通过扩展一个隐藏的面板。 But here both hidden panel and the next panel to the clicked panel get expanded. 但是这里隐藏的面板和点击面板的下一个面板都得到了扩展。

listeners:{
    afterrender: function(panel){
        panel.header.el.on('click', function() {
          if (panel.collapsed) {
             Ext.getCmp('hiddenpanel').collapse();
          }
          else {
             Ext.getCmp('hiddenpanel').expand();
          }
        });
    }
}

Is there any solution to solve this problem ? 有没有解决这个问题的方案?

Thanks 谢谢

If you are okay with opening multiple accordion items at a time, enable mutli property and set all other panels except the hidden panel collapsed by default will resolve the issue. 如果您可以一次打开多个手风琴项目,启用mutli属性并设置除默认情况下折叠的隐藏面板以外的所有其他面板将解决此问题。

Ext.create('Ext.panel.Panel', {
   title: 'Accordion Layout',
   width: 300,
   height: 300,   
   layout: {
      type: 'accordion',      
      animate: true,
      multi: true,
   },
   items: [{
      hidden:true,        
   },{
      title: 'Panel 1',
      html: 'Panel content!',
      collapsed: true
   },{
      title: 'Panel 2',
      html: 'Panel content!',
      collapsed: true
   },{
      title: 'Panel 3',
      html: 'Panel content!',
      collapsed: true
   }],
   renderTo: Ext.getBody()
});

Jsfiddle 的jsfiddle

Edit : For versions above Ext 5. 编辑 :对于Ext 5以上的版本。

Ext.application({          
    launch: function() {    
        Ext.create('Ext.panel.Panel', {
            renderTo: Ext.getBody(),
            autoScroll: true,
            defaults: {
                border: true,
                autoHeight: true,
                minHeight: 304,
                collapsed: true,
                titleCollapse: false
            },
            layout: {
                type: 'accordion',
                animate: true,
                multi: true,
                fill: false
            },
            items: [{
                collapsed: false,
                border: 0,
                height: 0,
                minHeight: 0
            }, {
                title: 'Panel 1'
            }, {
                title: 'Panel 2'
            }, {
                title: 'Panel 3'
            }, {
                title: 'Panel 4'
            }, {
                title: 'Panel 5'
            }],
        });    
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM