PDA

View Full Version : HOW TO: Move a TreeNode from one parent to another?



wgpubs
26 Apr 2011, 4:40 PM
I think the code I have is (mostly???) right. The problem is that the node is not visible underneath the new parent after the move. Here is what I got ... any help would be appreciated:



var userTreeLoader = new Ext.tree.TreeLoader({
dataUrl : myUrl,
listeners : {
beforeload : function(treeLoader, node) {
userTreeLoader.baseParams.treeName = "userTree";
userTreeLoader.baseParams.userID = userInfo["userID"];
userTreeLoader.baseParams.divisionID = userInfo["divisionID"];
}
, load : function(loader, node, response) {
Ext.getCmp('content-panel').layout.setActiveItem(2);
Ext.getCmp("content-panel").doLayout();
Ext.getCmp('westpanel').findById('userTree').expand();
Ext.getCmp('westpanel').findById('userTree').getRootNode().expandChildNodes();
Ext.getCmp('userTree').getNodeById('div_' + userInfo["divisionID"]).expand();
Ext.getCmp('userTree').getNodeById('user_' + userInfo["userID"]).select();
}
}
});

var userTree = new TrainingDB.DivisionTree({ id: 'userTree', title: 'Manage Users', autoWidth: true, loader: userTreeLoader });
userTree.on('click', function(node) {
Ext.getCmp('content-panel').layout.setActiveItem(2);
Ext.getCmp("content-panel").doLayout();
userGrid.loadUsers(node.attributes.divisionID, node.attributes.traineeID);
});

new Ext.tree.TreeSorter(userTree, {
folderSort: true,
dir: "asc"
});




... and here is my code to move to a new parent ...



var newDivTreeNode = Ext.getCmp('userTree').getNodeById("div_" + userDivisionId);
userTreeNode.attributes.divisionID = userDivisionId;
newDivTreeNode.appendChild(userTreeNode);



The node is removed from its previous parent properly. Problem it isn't visible under new parent even though I've verified in Firebug that it is there.

Thanks -wg