Results 1 to 4 of 4

Thread: Select node in treepanel when loaded

  1. #1
    Sencha User
    Join Date
    Jul 2009
    Location
    The Netherlands
    Posts
    196

    Default Select node in treepanel when loaded

    Hi all.

    I create a treepanel like this:

    Code:
            xtype: 'treepanel',
            id: 'UrenTreePanel',
            title: 'Week',
            region: 'west',
            collapsible: true,
            animCollapse: true,
            split: true,
            border: true,
            width: 200,
            minSize: 100,
            maxSize: 300,
            loader: new Ext.tree.TreeLoader(),
            root: new Ext.tree.AsyncTreeNode(
            {
                expanded: true,
                children: function()
                {
                    var myDate = new Date().add(Date.DAY, -10 * 7);
                    var nodes = new Array();
                    for(var i = 0; i < 10; i++)
                    {
                        myDate = myDate.add(Date.DAY, 7);
                        nodes[i] =
                        {
                            //text: 'Week ' + myDate.getWeekOfYear(),
                            text: myDate.getFullYear() + ' - ' + myDate.getWeekOfYear(),
                            leaf: true,
                            listeners:
                            {
                                click: function(node, e)
                                {
                                    // get week of node
                                    var array = node.text.split(' - ');
                                    var year = array[0];
                                    var week = array[1];
                                    
                                    dsHoursTotals.proxy = new Ext.data.HttpProxy({url: './data/json.php?sort=hours&action=get-totals&year=' + year + '&week=' + week});
                                    dsHoursTotals.reload();
                                }
                            }
                        };
                    }
    
                    return nodes;
                }()
            }),
    When the treepanel is loaded and rendered, i want it to automatically select the latest childNode. So i used this code:

    Code:
            listeners:
            {
                render: function(self)
                {
                    // selecteer de laatste week
                    self.root.lastChild.select();
                }
            }
    However, when it executes the code in the render event, lastChild is still null, so the nodes aren't loaded yet.

    So how can i select automatically the latest childNode in the treepanel after it has finished loading?

  2. #2

    Default

    any answer to this one?

  3. #3
    Sencha User
    Join Date
    Sep 2009
    Location
    Calgary, Alberta, Canada
    Posts
    638

    Default

    Have you tried using "afterrender", and instead of using:
    self.root, try self.getRootNode()

  4. #4

    Default

    I got this to work for a TreePanel:

    Code:
    listeners: {
                "load":function(node){
                	var me = this;
                	node.eachChild(function(childNode){
                    	me.removeListener("load",me.initialConfig.listeners.load);
                    	setTimeout(function(){
                    		childNode.expand();
                    	},1000);
                    });
                }
            },
    this runs at the correct time (once the child node has loaded), and then removes itself after the first time, since I only need to expand one level for my app.

    However, for some reason, the "childNode.expand()" call won't work without a timeout. There's no error at execution time, but if you try to open and close nodes afterward, you get an odd DOM exception-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •