2

I have a treepanel with nodes inside the treepanel. To identify whether the treepanel and not the nodes that are expanded or collapsed I use the following code:

Ext.getCmp('general').collapsed

The return value is either true or false. Is there an event in treepanel that I can capture when the treepanel is expanded or collapsed? I mean the treepanel and not the nodes in the panel.

Your help is kindly appreciated.

Thank You.

Eugene Anthony
  • 49
  • 1
  • 1
  • 11

3 Answers3

2

You must do something wrong here, the following code works, see this JSFiddle

Ext.create('Ext.tree.Panel', {
    collapsible: true,
    title: 'Simple Tree',
    width: 200,
    height: 150,
    store: store,
    rootVisible: false,
    renderTo: Ext.getBody(),
    listeners: {
        collapse: function() {
            alert('collapsed');
        },
        expand: function() {
            alert('expand')
        }
    }
});
sra
  • 23,820
  • 7
  • 55
  • 89
  • I tried adding the collapse and expand event in my listener and it still doesn't work. – Eugene Anthony Feb 20 '13 at 07:15
  • Then you'll need to share some more code, because this works for me and should work for you. Where and how do you declare the listeners? – Johan Haest Feb 20 '13 at 07:37
  • id: 'accountTreePnl', name: 'accountTreePnl', height: 250, xtype : "treepanel", rootVisible: false, border: false, animate : false, autoScroll : true, containerScroll : true, root: new Ext.tree.AsyncTreeNode({ text: 'Account(s)' }), loader: new Ext.tree.TreeLoader({ dataUrl: '' }), dropConfig : { appendOnly : true }, listeners: { collapse: function() { }, expand: function() { } } – Eugene Anthony Feb 20 '13 at 07:57
  • @EugeneAnthony based on that example your tree isn't collapsible at all. So I guess you are collapsing a container into which you have nested the tree? – sra Feb 20 '13 at 08:33
  • The tree panel is inside a panel that uses the fit layout. – Eugene Anthony Feb 20 '13 at 08:48
  • @EugeneAnthony Again; **based on that example your tree isn't collapsible at all!** It seems that you are collapsing the panel with the fit layout. In that case now event on treepanel get fired – sra Feb 20 '13 at 08:50
  • Done. Perhaps this question might interest you. http://stackoverflow.com/questions/14993104/extjs-combo-box-disabled-properties-not-functioning – Eugene Anthony Feb 21 '13 at 20:24
1

'expand' and 'collapse' don't work for me neither. Instead, 'itemcollapse', 'itemexpand', 'itemmove' and their peers do work for me. I'm with Ext-JS 4.2.1.

fraber
  • 1,204
  • 1
  • 8
  • 21
  • You used the wrong event. You need to use afteritemexpand event. afteritemexpand: function ( node, index, item, eOpts ){ alert('Dharmesh'); } Here's a fiddle: http://jsfiddle.net/johanhaest/RDC9W/1/ – Dharmesh Hadiyal May 25 '16 at 11:37
0

You used the wrong event. You need to use afteritemexpand event.

afteritemexpand: function ( node, index, item, eOpts ){
    alert('HAHA');
}

Here's a fiddle:

http://jsfiddle.net/johanhaest/RDC9W/1/

Dharmesh Hadiyal
  • 719
  • 1
  • 7
  • 18