Closed rosenfeld closed 12 years ago
You can use loadData to add a subtree to an existing tree.
var new_data = [
label: 'new_element'
];
$('#tree1').tree('loadData', new_data, existing_node);
Yeah, but how about adding a new root element?
That's not possible at this moment. I guess it should be possible because drag-and-drop does also add nodes in every position in the tree. I will look into it.
thanks :)
The dev branch has new functions addNodeAfter, addNodeBefore and addParentNode.
To add a new parent to node 'node1':
$('#tree1').addParentNode(
node1,
{
label: 'new_parent',
id: 456
}
);
By the way, for saveState to work, nodes in tree data must have an id field.
Thank you very much, I'll give it a try as soon as I finish implementing another feature I'm working right now.
But I'm already closing this issue because I believe on you ;)
Cheers!
By the way, I'm not using saveState because my tree is lazily evaluated... :)
I've started to give this a try today and it seems addNodeAfter is working fine. I don't need addParentNode so I'll probably not test it, but I intend to test addNodeBefore later.
But I guess I'm missing something because I couldn't find out how to remove some node. Is there any removeNode method or another way of doing that? Or am I supposed to do something like $(tree.tree('getNodeById', id).element).remove()?
I found removeChild, but how can I remove a root node?
node.parent.removeChild(node) worked for me :)
I will add a removeNode function
thanks, @mbraak :)
The removeNode function is now added to the dev branch
thank you! I'll give it a try in a few minutes
great! worked here, thanks! :)
I couldn't find any current API that would allow me to do that.
For example, in my application it is possible to create new elements in the tree dynamically.
Currently I'm refreshing the whole tree if I need to add another root element, while this also looses all information about collapsed and expanded nodes.
It would be handy if I could just append some element to the current tree. Is that already possible?