1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    18
    Vote Rating
    0
    raiwinashu is on a distinguished road

      0  

    Default Unanswered: Ext js 4:Acessing tree node

    Unanswered: Ext js 4:Acessing tree node


    Hi all,

    I am new to extjs.I have created Tree from Xml data generated using Generic handler.My requirement is that on clicking the child node i should be able to get the text of the node.Please someone help me to do this.
    This is my screen shot of the tree

    books.png
    I have used beforeitemclick event.I need to get node text (in my case "Plots").

    This is my code
    Code:
    var tstore = Ext.create('Ext.data.TreeStore', {
            fields: [{ name: 'leaf', type: 'bool', defaultValue: false, persist: false, mapping: 'Sno/@leaf' }, 'Bname'],
            proxy: {
                type: 'ajax',
                url: 'xmldata.ashx',
                extraParams: {
                    isXml: true
                },
                reader: {
                    type: 'xml',
                    root: 'Books',
                    record: 'Book'
                }
            },
            sorters: [{
                property: 'leaf',
                direction: 'ASC'
            }, {
                property: 'text',
                direction: 'ASC'
            }],
            root: {
                text: 'Books',
                id: 'id',
                expanded: false
            }
    
        });
    
        var tree = Ext.create('Ext.tree.Panel', {
            store: tstore,
            id: 'tree',
            columns: [
                        { dataIndex: 'Sno', text: 'Serial No', xtype: 'treecolumn' },
                        { dataIndex: 'Bname', id: 'no' }
                     ],
            renderTo: Ext.getBody(),
            height: 300,
            width: 250,
            title: 'Books',
            hideHeaders: true,
            rootVisible: true,
            // useArrows: true,
            dockedItems: [{
                xtype: 'toolbar',
                items: [{
                    text: 'Expand All',
                    handler: function () {
                        tree.expandAll();
                    }
                },
                    {
                        text: 'Collapse All',
                        handler: function () {
                            tree.collapseAll();
                        }
                    }]
            }],
            listeners: {
                beforeitemclick: function (cmp, record) {
                    
                    alert("Itemclick fired");
                }
            }
    
        });
    Regards
    Ashwin

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You have the record of the node you clicked on. You can get it from that.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,021
    Answers
    385
    Vote Rating
    183
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    To Mitchell's point you can use the record's get method using the property for the tree node title.

    i.e.
    Code:
    beforeitemclick: function (view, record) {
        alert(record.get('text'));
    }

Thread Participants: 2