Results 1 to 2 of 2

Thread: Select first children of TreePanel

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    59
    Vote Rating
    0
      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
    Answers
    347
    Vote Rating
    114
      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));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •