1. #1
    Ext User
    Join Date
    May 2008
    Posts
    11
    Vote Rating
    0
    goodwrench is on a distinguished road

      0  

    Default [FIXED] Cannot move TreeItem from one Tree to another

    [FIXED] Cannot move TreeItem from one Tree to another


    I'm trying to move selected items from one tree to another. Items are disappearing from the source tree, but not getting added to the destination tree. Looks like once the tree item is rendered, it is not getting added to the new TreeItemUI element anymore, even if it was previously removed from another tree.
    This is the sample code. It does not look really pretty, but illustrates the issue.
    Code:
     
    public void onModuleLoad() {
          Viewport viewport = new Viewport();
          viewport.setLayout(new FitLayout());
          HorizontalPanel mainPanel = new HorizontalPanel();
          
          final Tree<SingleTreeSelectionModel> source = new Tree<SingleTreeSelectionModel>();
          TreeItem item = new TreeItem("Move this  item");
          item.setId("id0");
          source.getRootItem().add(item);
          source.setSize(200, 200);
          mainPanel.add(source);
    
          Button move = new Button("Move");
          
          mainPanel.add(move, 
                  new TableData(Style.HorizontalAlignment.CENTER, Style.VerticalAlignment.MIDDLE));
          
          final Tree<SingleTreeSelectionModel> dest = new Tree<SingleTreeSelectionModel>();
          dest.setItemIconStyle("icon-music");  
          dest.setSize(200, 200);
          mainPanel.add(dest);
    
          move.addListener(Events.Select, new Listener<ComponentEvent>(){
    
                public void handleEvent(ComponentEvent be) {
                    TreeItem item = source.getItemById("id0");
                    source.remove(item);
                    dest.getRootItem().add(item);
                }
                  
              });
          
          viewport.add(mainPanel);      
          viewport.layout(true);      
          RootPanel.get().add(viewport);
      }

  2. #2
    Ext User
    Join Date
    Apr 2008
    Posts
    18
    Vote Rating
    0
    kcaseye is on a distinguished road

      0  

    Default


    I haven't tried do anything like that myself, but you may want to try "moving" the underlying data that is displayed by the tree item by using that data to create a new (identical) tree item in the second tree.

    So...
    1. Move event is triggered somehow
    2. Get data of item being moved
    3. Remove item from first tree
    4. Create new tree item with data
    5. Add new tree item to second tree

    I don't know if there is an easier solution, but I think this would work.

  3. #3
    Sencha - GXT Dev Team darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242
    Vote Rating
    2
    darrellmeyer is on a distinguished road

      0  

    Default


    Thanks for the code sample. There was a bug in TreeItem when adding rendered children. The fix is in SVN.

Thread Participants: 2