extjs treepanel expand collapse event

10,629

Solution 1

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')
        }
    }
});

Solution 2

'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.

Share:
10,629
Eugene Anthony
Author by

Eugene Anthony

Updated on June 04, 2022

Comments

  • Eugene Anthony
    Eugene Anthony almost 2 years

    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
    Eugene Anthony about 11 years
    I tried adding the collapse and expand event in my listener and it still doesn't work.
  • Johan Haest
    Johan Haest about 11 years
    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?
  • Eugene Anthony
    Eugene Anthony about 11 years
    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() { } }
  • sra
    sra about 11 years
    @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?
  • Eugene Anthony
    Eugene Anthony about 11 years
    The tree panel is inside a panel that uses the fit layout.
  • sra
    sra about 11 years
    @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
  • Eugene Anthony
    Eugene Anthony about 11 years
    Done. Perhaps this question might interest you. stackoverflow.com/questions/14993104/…
  • Dharmesh Hadiyal
    Dharmesh Hadiyal almost 8 years
    You used the wrong event. You need to use afteritemexpand event. afteritemexpand: function ( node, index, item, eOpts ){ alert('Dharmesh'); } Here's a fiddle: jsfiddle.net/johanhaest/RDC9W/1