-
Notifications
You must be signed in to change notification settings - Fork 177
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 loading - children #37
Comments
You could add a single phantom node to the children. Very sketchy sample code:
Catch the tree.open event. This event is fired when a node is opened.
|
Do you think that jqTree should add support for dynamically loading of children? If so, what should the API look like? |
Ok, the phantom node helps me. About second comment, I think it's interesting. |
Hello, It doesn't work! |
I made an example on http://jsfiddle.net/QAt6Z/6/ to demonstrate the idea. |
I'm using this exact technique here, so I guess it would be great to have some common API. In my case, instead of 'phantom' I use the "loading..." label and the "fetched" property to check if the children were already fetched or not. |
I can see that there is a need for lazy loading of nodes. I will look into it. |
Thank you! |
I'm still thinking about a good API for lazily loading nodes, but I haven't found a good solution yet. |
JqTree now supports load-on-demand. It's in the load-on-demand branch. There is no documentation yet, but there is an example in /examples/example5.html. |
Great, I'll try it soon |
Thanks! |
Could you please provide some hook for onLoadData() with the original data? The problem is that I need to keep the original one (containing 'label', for instance) |
So, just to make sure I understand you correctly. You want jQtree to fire an event when the data is loaded. And this event should have a link to the original loaded data. I think that is possible. I also think it should be a general event. So, it is fired when the initial data for the tree is loaded, and when data is loaded on demand. (And also when data is loaded without ajax, using the data option). Is this what you what you had in mind? By the way, thanks for the pull-request that fixes the load-on-demand example. |
Exactly, thanks :) No problem :) |
I added the tree.load_data event. It's in the load-on-demand tree. Detail: the data is in the event.tree_data property. The data property is already used by jQuery. |
Thank you so much. I could finally replace my custom handling with the built-in handling you have just implemented. :) |
I need more than one parameter of the node-id. Is there any way to pass additional parameters? |
At this moment that's not possible. |
And if we sent the node object as parameter, it would be a bad idea? |
I really believe this should be a GET request and I'm not sure if the node object would even be serializable to be sent in a POST request either. I also had to change my server code as my URLs were like /nodes_from_parent/324 and now the requests are like /nodes_from_parent?node=324. Maybe we could provide an option to the tree() call: $('#tree').tree( {
dataUrl: function(parentNode) {
return {
url: '/from_parent',
type: 'get',
data: { node: parentNode.id }
};
}
}); I guess something like that would be very flexible. |
Yes, that would be perfect. |
I guess it's possible to customize the url. And this looks like an elegant solution. So, your idea is: the dataUrl option can be a url, or it can be a function that returns an url object. What do you think of this?
|
Yep, that is exactly what I had in mind (except for the initial data, but I also agree on it). I guess you're talking about two possibilities: 1 - the function returns a string We should then issue a GET request to that string. 2 - the function returns an object Use like in my prior example And, of course, if dataUrl is a string itself, the current behavior would remain intact. |
Yes, those are the options. I think I'm going for the first option because that is the most simple one. |
Sorry, but I don't understand. They're not exclusive options. You can support all of them. Please let me know what do you think you need to decide between. |
I think that jqTree should support the following for dataUrl: string:
or a function that returns a string:
|
The problem with returning just a string is that you would be limited to GET requests only. Also, you'd need to encode the URL by yourself, while you could let jQuery handle it for you... I mean, returning a string would be good to my situation but not that good for @rat43. |
I'm guessing that a GET request will also work for rat43. |
But still he'll need to build the query string by himself, since he needs to send multiple parameters (data type and id). What if data type needs to be URL encoded? If he could just return an object with the data to be encoded, jQuery.ajax would take care of it. |
A GET request solve my problems. |
Yes, if you use the function, then no parameter is added. I'm still thinking about the url encoding. Is there another way to encode the parameters correctly? |
$.param({a: 1, b: 'a b'}) == "a=1&b=a+b" |
I updated the load-on-demand branch. It is now possible to use a function for the dataUrl option. Note that the function must return a url string. This was far easier to implement than the object version. Example:
|
Thank you, Marco |
Thanks, I'll look soon |
Any estimates about when this will be merged to master and released? I've already tested it on my application and it is working great. Maybe a loading indicator could be interesting if the network connection is pretty bad, but it is already good enough for me as it is. |
It's now in the master branch. This version is 0.12. By the way, jqTree does add a jqtree-loading class to the li that is being loaded. See examples/example.css. |
Humm... this is insteresting :) Thank you for letting me know. Looking forward to 0.12... |
At the first moment my tree contains only the root nodes and their children.
This children don't have children because they are loaded dynamically when the user clicks on the node (using loadData).
In this case, the layout doesn't show the arrows on the nodes that don't have children, but I need the arrows, for presentation issues.
To resolve this, I added an anchor with class="toggler closed", but this arrow doesn't have the open and close event.
How can I solve this case?
The text was updated successfully, but these errors were encountered: