khan4019 / tree-grid-directive

Need one or more maintainer for this! comment or email me if you are interested
http://khan4019.github.io/tree-grid-directive/test/treeGrid.html
347 stars 183 forks source link

Dynamic fetch children #130

Open kirajhpang opened 7 years ago

kirajhpang commented 7 years ago

Hi, I would like to know there is there possible to do dynamic fetch children from REST?

Example, every node will have + button no matter how, but when user click it, it trigger call and refresh this particular children to new array data set.

This will be great for optimizing, so that we can reduce time wait for first time call to initialize tree data.

torsten-sauer commented 7 years ago

Hi @kirajhpang,

sorry for my late response, but maybe it helps?

I did this some days ago with the following logic:

I hope this helps!

kirajhpang commented 7 years ago

@torsten-sauer hi, thanks for your update however, but I couldn't found out the way to load specific children form server and attach them to that branch ?

torsten-sauer commented 7 years ago

It surely depends on your backend and how you load the tree and it's children. You will need at least one function to get the root(s) of the tree and one function to get the children of a specific node.

If you know how to load these it is really simple to attach them. You can set the children attribute of the clicked branch and expand it.

To clarify: not the tree grid itself loads the nodes, you have to do this on your own and than attach them to the tree. So it really really depends where your tree data comes from and how do you load it.

kirajhpang commented 7 years ago

Actually, before raising this issues, I do create get tree and specific children feature on my backend service, but on that time I cannot find the way to assign this children array into that specific node.

I also remember, even I try to update tree element from angular controller, it seem no refresh the tree, on that time, what I can do for bypassing this is simply re-create the list for refresh it.

However, I will try your suggestion and look back this document if I have time, thanks for reply btw.

torsten-sauer commented 7 years ago

If you use the on-click you get the single node/branch of the tree. You need to set the children property of the given branch and set the expanded property to true - that should do the trick. You don't need to update the whole tree data, only the selected/clicked branch.