PDA

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



vick_44
6 Sep 2016, 2:48 AM
Possibly duplicate of

https://www.sencha.com/forum/showthread.php?95302-Select-First-Node-In-A-Tree-after-Render

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.


references:


https://www.sencha.com/forum/showthread.php?95302-Select-First-Node-In-A-Tree-after-Render
http://jsfiddle.net/TBa2E/




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'}
],
proxy:{
type: 'ajax',
url: 'data/menuTree.json',
reader:{
type:'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: {
afterrender:function(){
debugger;
var record = this.getStore().getNodeById('search');
this.getSelectionModel().select(record);
}
}
});

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.
https://fiddle.sencha.com/#fiddle/1k31

vick_44
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.