Is there a way to change node text in bootstrap treeview?

3.6k Views Asked by At

Is there a way to change node text in bootstrap treeview without redrawing the whole tree or removing/adding the node?

I checked here: https://github.com/jonmiles/bootstrap-treeview and here: https://github.com/patternfly/patternfly-bootstrap-treeview but there seem to be no method like "updateNode" or "renameNode".

2

There are 2 best solutions below

2
Rony On BEST ANSWER

Simply select the node and update its parameters -

node = $('#tree').treeview('getNode', <nodeId>);
node.text = '<new value>';
$('#tree').treeview(true).removeNode([]); // refresh hack available in the development github branch.
0
Grobderf On

I am using the following code to change the tree node, without having to update the whole view.

var e = $(node.$el).find(".text");
e.html(value);

But in order for that to work, you have to set wrapNodeText to true, as this creates a span.text around the text, which make it possible to change.