David
David

Reputation: 4271

How to fire event when click on only last child element of treepanel in EXTJS

I have treepanel. I want to fire an event on click of only child element.

In my itemclick event it is firing all the time when I click. I want only to fire only when the last child is clicked.

Eg.: It should fire "Manage Application Child" not on the "Manage Application"

var root = {
    expanded: true,
    children: [{
        text: "Configure Application",
        expanded: true,
        children: [{
            text: "Manage Application",
            children: [{
                text: "Manage Application Child",
                leaf: true
            }]
        }, {
            text: "Scenario",
            leaf: true
        }]
    }, {
        text: "User Configuration",
        expanded: true,
        children: []
    }, {
        text: "Test Configuration",
        //leaf: true,
        expanded: true,
        children: [{
            text: "Manage User",
            leaf: true
        }, {
            text: "User rights",
            leaf: true
        }]
    }]
};

{
    xtype: 'treepanel',
    useArrows: true,
    autoScroll: false,
    animate: true,
    enableDD: false,
    title: 'Configuration',
    width: 200,
    height: 400,
    rootVisible: false,
    store: Ext.create('Ext.data.TreeStore', {
        root: root
    }),
    listeners: {
        itemclick: function (s, r) {
            alert(r.data.text);
        }
    }
}

Upvotes: 0

Views: 541

Answers (2)

Chintan Kukadiya
Chintan Kukadiya

Reputation: 784

I created FIDDLE i think it will help you what you want

Upvotes: 0

Fabio Barros
Fabio Barros

Reputation: 1439

If i understand correctly, you just have to check if the node is "leaf":

           itemclick: function (s, r) {
                if (r.data.leaf){ //or r.data.children == null
                    alert(r.data.text);
                }                 
            }

Upvotes: 3

Related Questions