-
4 May 2012 12:18 PM #1
Answered: Select first children of TreePanel
Answered: Select first children of TreePanel
Hello together
Why doesn't the following code work in Ext JS 4.1 final?
In Ext JS 4 RC3 the above code works as expected.Code:Ext.onReady(function() { var store = Ext.create('Ext.data.TreeStore', { root: { expanded: true, children: [ { text: "Item 1", leaf: true }, { text: "Item 2", leaf: true } ] } }); var tree = Ext.create('Ext.tree.Panel', { store: store, rootVisible: false }); Ext.create('Ext.container.Viewport', { layout: 'border', items: [{ region: 'west', collapsible: true, title: 'TreePanel', width: 200, split: true, layout: 'fit', items: [ tree ] }] }); tree.selectPath(tree.getRootNode().getChildAt(0).getPath()); });
How can I achieve that the 1st children in the TreePanel will be selected in Ext JS 4.1 final?
Thanks for your help!
Kind regards, extjser12
-
Best Answer Posted by vietits
Some solutions for your case:
1. Specifying a field for getPath() and setPath(). One thing to remember is that this field should make the path unique. So it's better to define id for each node and use that field (default field is determined by idProperty)
2. Use SelectionModelCode:tree.selectPath(tree.getRootNode().getChildAt(0).getPath('text'), 'text');
Code:tree.getSelectionModel().select(tree.getRootNode().getChildAt(0));
-
4 May 2012 3:17 PM #2
Some solutions for your case:
1. Specifying a field for getPath() and setPath(). One thing to remember is that this field should make the path unique. So it's better to define id for each node and use that field (default field is determined by idProperty)
2. Use SelectionModelCode:tree.selectPath(tree.getRootNode().getChildAt(0).getPath('text'), 'text');
Code:tree.getSelectionModel().select(tree.getRootNode().getChildAt(0));


Reply With Quote