mbraak / jqTree

Tree widget for jQuery
https://mbraak.github.io/jqTree/
Apache License 2.0
1.02k stars 177 forks source link

Load / append data on click of node #10

Closed aaronlcope closed 12 years ago

aaronlcope commented 12 years ago

I don't see a way to append new data to an existing node when you click it. Is there a way to issue an ajax request for more data under a particular node and have this plugin append more nodes via JSON formatted responses?

If this already exists, is there any sample code anywhere?

mbraak commented 12 years ago

At this moment it's not possible to add nodes dynamically to the tree. I think it would be a nice feature, though.

It is possible to load a whole new tree using the function loadData (http://mbraak.github.com/jqTree/#functions-loadData).

mbraak commented 12 years ago

The 'dev' branch contains a new feature for loading a subtree. The function 'loadData' now accepts a 'parent_node' parameter.

$tree.tree('loadData', data, parent_node);

Example for loading subtree on click:

$('#tree1').bind(
    'tree.click',
    function(e) {
        var node = e.node;

        $.getJSON(
            '/get-data/',
            function(data) {
                $tree.tree('loadData', data, node);
            }
        );
    }
);
mbraak commented 12 years ago

Implemented in version 0.7

rosenfeld commented 12 years ago

There is still an issue here. 'tree.click' event won't be always triggered. For example, if you try to move a node to inside a closed node, it will open the node but won't trigger the 'tree.click' event.

I'll create a separate issue since this was already closed.