wix-incubator / angular-tree-control

Angular JS Tree
http://wix.github.io/angular-tree-control
MIT License
708 stars 277 forks source link

Programmatically collapsing a node #245

Open mostlybob opened 8 years ago

mostlybob commented 8 years ago

(still pretty new to Angular and the tree control)

I'm using the tree control to display a hierarchy structure for an organization. The nodes are of two types: Members and Groups. I lazy load the child nodes on Group nodes so they only hit the server when the node is expanded. For Groups, I have a placeholder node, called Loading, as the only item in the children collection. When the Group node is expanded I make a server call and repopulate the child nodes with data from the server.

I have a need to move nodes from one Group to another. This involves capturing the target Group node id and issuing a call to the server to reassign the Group or Member to the new Group. I then requery the target Group to show the updated child node collection. In the case of Group nodes, if the node is expanded and showing its members and child groups then it appears on the target Group expanded, but instead of the child Members and Groups, it shows the Loading placeholder node. I would expect this behavior because of the lazy loading only showing the topmost level of groups. What I would like to do is have the node at the top level be collapsed.

I tried working the the expanded nodes collection, but could not get that to go.

I saw the issue at https://github.com/wix/angular-tree-control/issues/14 and the means of collapsing the node:

angular.element('#tree').controller('treecontrol').collapseNode(/*node reference*/);

although from the comment, I'm not sure it was actually implemented. I have tried a couple of values for treecontrol above, the literal 'treecontrol' which is the name of the ATC element as well as the controller name defined at the top level div with the ng-controller attribute.

This seems like a good feature to have and if it's available now, I know there's probably something pretty basic I'm missing. Thanks for any insight you can give.