2 Replies Latest reply on Mar 20, 2007 6:12 AM by JKohn99

    Navigating through a tree

    JKohn99 Level 1
      I have the following situation:
      A user navigates through a tree.
      - at some point the issue a command to add a new entry to the tree.
      - The back end responds with a new set of data (with the new item added)
      - I replace the trees data provider
      - I want to scroll back to the node where the user initiated the command.

      I can find the node in the data provider collection that I want to display,
      but I can't get the tree to scroll to that point.

      Any input or things to try would be appreciated.
        • 1. Re: Navigating through a tree
          ntsiii Level 3
          It will be more thatn a "scroll" though, you will have to open the branch(s) down to the previously selected node.

          Look into the selectedItems array. I just am not sure that this will work if the tree has new data, since the refrences will no longer be valid.

          You may have to do this manually, by saving an id for the selected node, then finding it and opening up the ancestor node chain after the dataProvider is reset.

          This is not hard, especially with e4x. Here is an example that will get you partway:

          • 2. Navigating through a tree
            JKohn99 Level 1
            Thanks for the reply. a few more details:

            If the tree is large enough a scrollToIndex is required to scroll the node into view.

            In the example on cflex, I quadrupled the size of the tree (to more closely match my application). When searching for a node near the bottom node was expanded but not visible. So I added:

            var idx:int = myTree.selectedIndex;

            Also in my application I am replacing the dataprovider with a new collection from the backend. So I also
            needed to add: myTree.validateNow();

            One more note: In the same tree I decided to implement a search function to allow users
            to find specific nodes. during expandNode I would intermittantly get an ActionScript error.
            We determined (with the help of Flex Support - thanks Peter) that a call to validateNow() was
            needed while iterating and expanding the parent tree nodes.