View Full Version : Select node in treepanel when loaded

12 Nov 2009, 2:58 AM
Hi all.

I create a treepanel like this:

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

return nodes;

When the treepanel is loaded and rendered, i want it to automatically select the latest childNode. So i used this code:

render: function(self)
// selecteer de laatste week

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?

21 Apr 2010, 7:23 AM
any answer to this one?

21 Apr 2010, 10:28 AM
Have you tried using "afterrender", and instead of using:
self.root, try self.getRootNode()

21 Apr 2010, 11:49 AM
I got this to work for a TreePanel:

listeners: {
var me = this;

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-