2

is it somehow possible to insert a Node with getorgchart.js without expanding the node directly? I want to dynamically insert a node (with the insertNode method). But the node should be collapsed.

Is it maybe somehow possible in the renderEvent or updatedEvent methods? I'm trying to implement a kind of lazy loading feature where the nodes are dynamically loaded + inserted.

Tobi Weißhaar
  • 1,617
  • 6
  • 26
  • 35

2 Answers2

3

You can use "expandOrCollapse" method provided by the api which takes node id as parameter and expand or collapse the specific node based on its state. e.g. expandOrCollapse(id). Where 'id' is node id which is just created. So after creating the node just call above line of code. For more details you can refer to below link: http://www.getorgchart.com/QuickStart/Methods/expandOrCollapse.html

  • The problem is that when I insert the node and afterwards I use the "expandOrCollapse" method then the inserted node can be seen by the user before it will be collapsed. I don't want that. But I was able to get it working. See my answer below. – Tobi Weißhaar Aug 24 '17 at 22:52
2

I was finally able to insert the node without expanding the node directly. I set the args.node.collapsed attribute to 1 when the node is rendered. So the node is collapsed after rendering.

function renderNodeEvent(sender, args) {
    args.node.collapsed = 1;
}

orgChart.insertNode(ID);
Tobi Weißhaar
  • 1,617
  • 6
  • 26
  • 35