PDA

View Full Version : How to insert a node after selected node?



Nikolajtesla
7 Nov 2010, 3:55 AM
I need to insert a new node into my treepanel.

Here is what I have done:

var newNode = new Ext.tree.TreeNode({id: 100, leaf: false, text: "just added"});
tree.selModel.selNode.parentNode.insertBefore(newNode, tree.getSelectionModel().getSelectedNode());The question is:


Why the node I have added is shown as a leaf, if i explicitly defined it as NOT leaf?
How i can actually insert a node AFTER selected node, not before? I looked for method insertBefore, but there is nothing like this.

darthwes
7 Nov 2010, 7:50 AM
1. Because it doesn't have any children. Did you mean new Ext.tree.AsyncTreeNode?
2. You have the TreeNode method appendChild and, as you've discovered, insertBefore. So you should be able to insert the node before any other node, or at the end. That should cover every use case.

Nikolajtesla
8 Nov 2010, 5:45 AM
If you are right, please tell how I suppose to insert a node in such situation
- node1
- node2
- node3
- node4
- node5

node2 is selected. So if i use insertBefore, a tree will be a below:
- node1
- nodeXXX
- node2
- node3
- node4
- node5

if i will use appendChild
- node1
- node2
- node3
- node4
- node5
- nodeXXX

But i need the nodeXXX to be inserted after node2

darthwes
8 Nov 2010, 6:20 AM
Select node 3 and insert before it?

Nikolajtesla
8 Nov 2010, 10:15 AM
Of course it's a possible solution, to find next node after a selected his node and insert a node before. If there is no next node just use appendChild.
I've thought about it. But it seems for me a little weird and complicated, therefore I gave it another chance and have asked if there any easier way ho handle this situation. If there is not, I will do it this way.

Thanks for help