Skip to content
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

Collapsing the tree? #19

Closed
sebakerckhof opened this issue May 6, 2012 · 13 comments
Closed

Collapsing the tree? #19

sebakerckhof opened this issue May 6, 2012 · 13 comments

Comments

@sebakerckhof
Copy link

Hello,

Thanks for this plugin!
Is there a way to collapse the tree or certain nodes of the tree?

Thanks in advance,
seba

@mbraak
Copy link
Owner

mbraak commented May 6, 2012

You can use the autoOpen option to open nodes when the tree is loaded. See http://mbraak.github.com/jqTree/#tree-options-autoopen

You can also use the openNode function to open a node programmatically. This function is not documented yet.

For example in demo.html:

var node = $('#tree1').tree('getNodeById', 23);
$('#tree1').tree('openNode', node);

@sebakerckhof
Copy link
Author

But that will expand the tree, I want to do the opposite, so collapsing (closing) the tree

@mbraak
Copy link
Owner

mbraak commented May 6, 2012

Oops. There is no function for that yet. Would be a nice feature for the next release.

@mbraak
Copy link
Owner

mbraak commented May 7, 2012

The dev branch now contains the function closeNode.

var node = $('#tree1').tree('getNodeBydId', 23);
$('#tree1').tree('closeNode', node);

To close a node without animation:

$('#tree1').tree('closeNode', node, true);

@jprf
Copy link

jprf commented May 21, 2012

Hello,

Is there a way to do an expand all/collapse all?

Thanks,
~/Jota

@mbraak
Copy link
Owner

mbraak commented May 21, 2012

jqTree has no function for that.

You could do something like this:

var $tree = $('#tree1');
$('#collapse').click(function() {
  var tree = $tree.tree('getTree');
  tree.iterate(function(node) {

    if (node.hasChildren()) {
      $tree.tree('closeNode', node, true);
    }
    return true;
  });
});

$('#expand').click(function() {
  var tree = $tree.tree('getTree');
  tree.iterate(function(node) {

    if (node.hasChildren()) {
      $tree.tree('openNode', node, true);
    }
    return true;
  });
});

@arunkumar2014
Copy link

Hello
I need to append my child node below their parent node dynamically from db through ajax call. I tried with openNode, addNodeAfter its not viewing. But i tried with append node its showing the child node last of all the parent node.

@mbraak
Copy link
Owner

mbraak commented Mar 28, 2016

Let me see if I understand you correctly. You want to add a child node to a parent node; the new node must be the first child.

Is that correct?

@arunkumar2014
Copy link

yes

@mbraak
Copy link
Owner

mbraak commented Mar 28, 2016

There is no 'add-first-child' function. But you can use the addNodeBefore function.

Here is an example:

// appendNodeFirst: add 'new_node' as first child to 'parent_node'
function appendNodeFirst($tree, new_node, parent_node) {
    if (parent_node.children && parent_node.children.length != 0) {
        // Parent has children; add before first child
        var first_child = parent_node.children[0];

        $tree.tree('addNodeBefore', new_node, first_child);
    }
    else {
        // Parent has no children; append node
        $tree.tree('appendNode', new_node, parent_node);
    }
}

var parent_node = $tree.tree('getNodeById', 1);

var new_node = {
    label: 'new child',
    id: 6
};

@urprasu
Copy link

urprasu commented May 5, 2016

how to merge the nodes

@urprasu
Copy link

urprasu commented May 5, 2016

how to replace rootnode child nodes

@mbraak
Copy link
Owner

mbraak commented May 5, 2016

@urprasu
Can you give give an example of how you want to merge nodes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants