View Full Version : Selecting first node In a Tree panel after rendering

6 Sep 2016, 2:48 AM
Possibly duplicate of


But i dint wanted to reopen an old thread and i am using extjs 4.1.1.

I have a treepanel where none of the leafs are selected by default, i want the first leaf need to be selected by default. I found few solutions on the internet where it shows how to do that, but it doesnt seem to work for me. Below is the code that i am using. This is part of a bigger application. When i place a debugger in afterrender listener, and execute the lines one by one the code works but If i remove the debugger then it doesnt. I am suspecting it may be due to timing, that is, when i place debugger, i am giving sufficient time for the application to load completely.

Is there any possible way around my problem?.
any help is deeply appreciated.



my code:

Ext.define('XXXXXXX.store.shared.MenuTreeStore', {
extend: 'Ext.data.TreeStore',
requires: 'XXXXXXX.model.shared.MenuTreeModel',
model: 'XXXXXXX.model.shared.MenuTreeModel',
autoLoad: true,
autoSync: true,
clearOnLoad: true,
clearRemovedOnLoad: true

Ext.define('XXXXXXX.model.shared.MenuTreeModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'text', type: 'string'}
type: 'ajax',
url: 'data/menuTree.json',

Ext.define('XXXXXXX.view.shared.MenuTreePanel', {
extend: 'Ext.tree.Panel',
alias : 'widget.XXXXXXX.view.shared.MenuTreePanel',
store: 'XXXXXXX.store.shared.MenuTreeStore',
id: 'XXXXXXX-view-shared-MenuTreePanel-Id',
useArrows: true,
rootVisible: false,
cls: 'no-leaf-icons',
height: 340,
minHeight: 340,
padding: 0,
bodyPadding: 0,
border: false,
renderTo: Ext.getBody(),

listeners: {
var record = this.getStore().getNodeById('search');

Gary Schlosberg
8 Nov 2016, 2:16 PM
I wasn't able to run your test case, but I put your code into this Fiddle, and it seems to run as expected.

27 Nov 2016, 11:25 PM
Yes it working now, not sure why my application wasnt behaving as its supposed to but now its resolved. Dont see above behaviour. Thanks Gary.

Gary Schlosberg
29 Nov 2016, 7:39 AM
Great, glad to hear it's working for you now.