1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    59
    Vote Rating
    0
    extjser12 is on a distinguished road

      0  

    Default Answered: Select first children of TreePanel

    Hello together

    Why doesn't the following code work in Ext JS 4.1 final?
    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());
    });
    In Ext JS 4 RC3 the above code works as expected.

    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

  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)
    Code:
    tree.selectPath(tree.getRootNode().getChildAt(0).getPath('text'), 'text');
    2. Use SelectionModel
    Code:
    tree.getSelectionModel().select(tree.getRootNode().getChildAt(0));

  3. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    112
    Answers
    347
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default

    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)
    Code:
    tree.selectPath(tree.getRootNode().getChildAt(0).getPath('text'), 'text');
    2. Use SelectionModel
    Code:
    tree.getSelectionModel().select(tree.getRootNode().getChildAt(0));

Thread Participants: 1