How to expand all ancestor nodes by a child node (selected or actived) automatically?

155 views
Skip to first unread message

huna...@gmail.com

unread,
Jun 22, 2014, 12:29:31 AM6/22/14
to fanc...@googlegroups.com
I got tree data like this :

var treeData = [
{
title : "Root Node", folder : true, key : "id1",
children : [
{ title : "Sub-item 1.1", key : "id1.1" },
{
title : "Sub-item 1.2", folder : true, key: "id1.2",
children : [
{ title : "Sub-item 1.2.1", key : "id1.2.1" },
{ title : "Sub-item 1.2.2", key : "id1.2.2" },
{
title : "Sub-item 1.3.1", folder : true, key : "id1.3.1",
children : [
{ title : "Sub-item 1.3.1", key : "id1.3.1" },
{ title : "Sub-item 1.3.2", key : "id1.3.2", active : true, selected: true },
{ title : "Sub-item 1.3.3", key : "id1.3.3" }
]
}
]
}
]
}
];

The forth level "Sub-item 1.3.2" has attribute 'avtive' and 'selected',

is there any way to expand it's ancestor node by giving a parameter to the $.fn.fancytree({ ... }) method, or just find ancestor node and set the 'expanded' attribute to 'true'?

Hurga Gonzales

unread,
Nov 9, 2015, 2:43:53 AM11/9/15
to Fancytree Q&A
Hi there

although your post is old I want to give you a workaround.
This script expands all parents to a n active subnode. The developer of FancyTree opened an issue at GitHub to get the built in solution to work. Until then you can use my solution:

init: function(event, data) {
var activeJumpNode = data.tree.getActiveNode();
if ( activeJumpNode ) {
var treeObj = $("YourSelector").fancytree("getTree");
var jumpToNode = treeObj.findFirst(function(node) {
return node === activeJumpNode;
});
jumpToNode.setActive();
jumpToNode.setFocus();
$(treeObj.$container).focus();
}
}





Gabriel Alejandro López López

unread,
Feb 21, 2022, 10:52:19 AM2/21/22
to Fancytree Q&A
Does this was finally solved? I'm implementing my own solution, but perhaps there is something built in.
Reply all
Reply to author
Forward
0 new messages