tree-grid-directive icon indicating copy to clipboard operation
tree-grid-directive copied to clipboard

Dynamic fetch children

Open kirajhpang opened this issue 8 years ago • 5 comments

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.

kirajhpang avatar Feb 13 '17 07:02 kirajhpang

Hi @kirajhpang,

sorry for my late response, but maybe it helps?

I did this some days ago with the following logic:

  • I changed the template for my grid to change the ng-click of the row icon to call the on_user_click (same as clicking on the expand property)
  • I used the on-click from the directive to attach my own handler
  • in this handler I check if the branch (that is given as parameter to the handler) is expanded or not
    • if the branch is already expanded, i close it
    • if the branch is not expanded, I load it's children from the server and attach them to the branch

I hope this helps!

torsten-sauer avatar Mar 21 '17 20:03 torsten-sauer

@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 ?

kirajhpang avatar Mar 22 '17 02:03 kirajhpang

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.

torsten-sauer avatar Mar 22 '17 18:03 torsten-sauer

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.

kirajhpang avatar Mar 23 '17 06:03 kirajhpang

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.

torsten-sauer avatar Mar 23 '17 10:03 torsten-sauer