2

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".

Joe Schmoe
  • 1,574
  • 4
  • 23
  • 48

2 Answers2

1

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.
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
Rony
  • 142
  • 2
  • 7
  • I accepted this as an answer but to be honest I already switched to jsTree. It seems it has much larger user base and getting help is easier. – Joe Schmoe Jul 13 '17 at 11:46
  • Right, the treeview indeed lack some basic functionalities (adding/removing nodes), I remember I had to initialize it every time the tree changed. Good luck. – Rony Jul 20 '17 at 14:32
0

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.

Grobderf
  • 3
  • 1
  • 3