QTree - Reload or refresh the tree (lazy loading enabled)

  • Hi,
    I am trying to reload my lazy loading tree to its initial state. On clicking the reload button, I clear the expanded array, root nodes and call my init function. Now, the root nodes are added but are not expandable. Any ideas? This is the sample code that I use:

    this.selected = ''
    this.expanded.length = 0
    this.rootNodes.length = 0
    this.initTree() //calls the ajax method which has this.rootNodes.push(....)

    But the root nodes added to the tree after reloading are not expandable. I may be doing this the wrong way. Any help would be appreciated. Thanks.

  • @rstoenescu Is refreshing the tree possible? Any other method?

  • Admin

    You’re in full control of what QTree displays. If you need same nodes to maintain the expanded state, then don’t reset this.expanded 🙂

  • @rstoenescu Thanks for your reply. But the whole issue is that I need to reset my entire tree without maintaining the state.

    However, I’ve also noticed that when I dynamically add a node that was previously a part of the expanded array before it was removed, the newly added node with the same old key is not expandable anymore with lazy load switched on. The toggle arrow does not show up. This may be related to the same issue I’ve mentioned above.

  • Admin

    Please do a jsfiddle and I’ll show you where you go wrong.

  • @joeyezekiel, I think this happens if you use lazy load AND mess with the model (:nodes) after initialization. You might provide your own ‘lazy load’ implementation.

    Using the Vue dev tools inspecting QTree’s state, I see that changes to “expanded.sync” are indeed reflected in the tree’s internal state. However, when reloaded, for every node in the expanded array the “@onlazyload” method would have to be fired, but this does not happen.
    My assumption: the tree does only know about the nodes of the inital model provided. Since the “@onlazyload” handler is never triggered it will not load the children of the expanded nodes and keep them closed.