Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic fetch children #130

Open
kirajhpang opened this issue Feb 13, 2017 · 5 comments
Open

Dynamic fetch children #130

kirajhpang opened this issue Feb 13, 2017 · 5 comments

Comments

@kirajhpang
Copy link

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
Copy link

torsten-sauer commented Mar 21, 2017

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!

@kirajhpang
Copy link
Author

@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
Copy link

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
Copy link
Author

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants