Callback for asynchronous Tree.open() calls

I have a tree with dynamic loading enabled. I need to open a specific path inside the tree programmatically. The problem is that after calling open(id) on the tree, there is no built-in way to know when the node has actually been opened.

Currently, I have two options:

  • Use window.setTimeout() to proceed every 500ms, which is very slow and may fail if the request takes too long
  • Send the entire path to the server and let it return the required part of the tree in one request (Edit: This doesn't even work since I can't control the request sent by open())

Is there another way to do this that I missed?

Comments

  • edited January 2015

    It is possible but not trivial.
    Check the next snippet http://webix.com/snippet/35ef9fe4

    It uses onDataRequest to set the promise and in onAfterOpen it runs the code only when promise is resolved. As result you can call any operations against child items and it will work for both loaded and not loaded yet branches.

    This doesn't even work since I can't control the request sent by open

    You can use onDataRequest event to intercept the data loading call and replace it with custom ajax call

  • Thank you, maksim, for your response. I will try both methods out.

  • I now use the onDataRequest and onAfterOpen methods and it does exactly what I needed. Thanks! Your support is amazing!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!