1. #1
    Sencha User
    Join Date
    Nov 2008
    Posts
    163
    Vote Rating
    0
    wgpubs is on a distinguished road

      0  

    Question Simulate TreeNode click in TreePanel programmatically?

    Simulate TreeNode click in TreePanel programmatically?


    I'm trying to figure out how, if possible, to programmatically select and then simulate a click on that selected node.

    So far I have this ...

    Code:
    var tree = Ext.getCmp('site_tree');
    tree.root.reload(function(){
         tree.getSelectionModel().select(tree.getNodeById(a.result.site_id));
    });
    Is there a way to simulate a click?

  2. #2
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    you can manually fire the click event if you want. What is the reason you want to do this?

  3. #3
    Sencha User
    Join Date
    Nov 2008
    Posts
    163
    Vote Rating
    0
    wgpubs is on a distinguished road

      0  

    Default


    I figured out a more straightforward way around this.

    What I was doing is opening a window with a form to create a new record in my database. After persisting the data and closing the form I wanted to refresh the tree so it showed the new record, selected it and fired the click event for that node so as to load the data into a new form for further editing.

    Just out of curiousity though ... how do you programmatically fire an event for a given node?

    Thanks

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,544
    Vote Rating
    64
    Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough

      0  

    Default


    Call the fireEvent method?

  5. #5
    Sencha User brunofin's Avatar
    Join Date
    Jun 2014
    Location
    Brazil
    Posts
    19
    Vote Rating
    1
    brunofin is on a distinguished road

      0  

    Default


    Sorry for grave digging, but I think this is useful for those who arrive from search engines.

    This thread is about ExtJS 2 BTW.
    On ExtJS 4 you can do like this:

    Code:
    tree.getSelectionModel().select(record);
    http://localhost/extjs/docs/index.ht...-method-select

  6. #6
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,099
    Vote Rating
    96
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    just to add if someone else is looking for similar issues. select() works but it doesnt fire the itemclick event. so in case you have a listener for itemclick and want to trigger that also, you can use fireEvent() with 'itemclick' for tree after select. for example, when the user clicks on a parent node, I want to select the first child node and fire itemclick for the child node:

    Code:
    listeners:
    {
      itemclick: function(view, record)
      {
        if(record.childNodes.length)
        {
           var firstChild = record.childNodes[0]; 
           tree.getSelectionModel().select(firstChild);
           tree.fireEvent('itemclick', view, firstChild);
        }
      }
    }