mbraak / jqTree

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

Issue in appending a child nodes #299

Closed sunnychaudhari closed 10 years ago

sunnychaudhari commented 10 years ago

Hey, I have an issue with appending child nodes to the tree. Scenario is, I want to load the tree nodes onclick of node arrow using an ajax call. So, for getting tree structure initially am passing just the root level nodes to the tree, and the tree works fine , but when i click on arrow , it goes for an ajax call, it takes the next level of node hierarchy but it overrides the previous tree structure.

I have :

<script type="text/javascript">
$(document).ready(function() {
    $(function() {
          var $tree = $('#themes');
            $tree.tree({
                autoOpen: false,
                        dataUrl: "{% url 'get_root_hierarchy' grpid node.pk %}",
                });

            $tree.bind(
                'tree.open',
                function(event) {
                    var node = event.node;                  
                    $.ajax({
                      async : true,
                      type: "GET",
                      url: "{% url 'get_hierarchy' grpid %}?id=" + node.id,
                      datatype: "html",
                      success: function(data) {
                                          var data = $.parseJSON(data) ;
                                          $tree.tree({
                                              data:data
                                          });        
                      }

                    });
                }
            );

        });

});
</script>

<div id="themes">  </div>

When we click on arrow for ajax call ,this manipulates and send the child nodes hierarchy, ajax success function receives the output properly, but it overrides the whole tree structure and then shows the new structure for that clicked node. I wanted to append the child structure to the previous node structure, please suggest me how to acheive that,

mbraak commented 10 years ago

Hello,

You can use the loadData function to load data in a subtree.

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

There is also the loadDataFromUrl function.

$tree.tree('loadDataFromUrl', url, node);

Your code looks a lot like load-on-demand, which jqTree already supports. See this example.

Greetings, Marco

sunnychaudhari commented 10 years ago

I tried this but its not working .

I am getting the list of childrens on click of tree node from an ajax call , as you can see in success function of ajax i receives the data in json format, which is list of childrens of that particular clicked node, but i want to append that new structure which came from ajax call to the previous tree structure.

Please suggest solution

mbraak commented 10 years ago

I don't have a solution for that.

sunnychaudhari commented 10 years ago

Ok, Thanks