Description
This issue is currently deferred
Due to low priority and current lack of resources, this issue was tentatively put aside.
See also info about deferred issues
Hello,
I use the fancytree with selectMode=3. I want to show a tree with pre-selected nodes (checkboxes) but fancytree ignores all "selected:true" definitions on nodes which have children.
My setup:
HTML:
<div id="tree"></div>
Javascript:
$('#tree').fancytree({
source: [
{ id: 1, key: 'A', title: 'A', children: [
{ id: 2, key: 'B', title: 'B', selected: true, children: [
{ id: 3, key: 'C', title: 'C' }
]}
]}
],
icon: false,
checkbox: true,
selectMode: 3
});
Expected and actual behavior
If "B" has definition "selected:true" then also "A" and "C" should be pre-selected. But actual no checkbox is checked => BUG
If I read out the FancytreeNode of the "B" then the property "selected" is set to "false"
var tree = $('#tree').fancytree('getTree');
console.log(tree.getNodeByKey('B').selected);
Additional info
If I move the "selected:true" definition to a leaf of the tree, e.g. to "C" node, then everything is fine and all 3 nodes are checked.
If I set the selectMode to 1 or 2, the "B" node is preselected without any problems. So it is a "selectMode=3" problem.
Steps to reproduce the problem
I have created a jsfiddle for this issue:
https://jsfiddle.net/x36krqL6/1/
Environment
- Browser type and version: Chrome 49
- jQuery and jQuery UI versions: jQuery 1.12.2 and jQuery UI 1.10.4
- Fancytree version: 2.16.1
UPDATE 1
It seems the function "fixSelection3FromEndNodes()" is the root cause. Before this function call the "selected" of node "B" is true and after this call the "selected" of "B" is false.
At the end of function "treeLoad":
if( ctx.options.selectMode === 3 ){
tree.rootNode.fixSelection3FromEndNodes();
}
There is also a comment for this fix-method, which says "Only end-nodes are considered to update the descendants branch and parents." Why?
In my case, I want to show a organization tree, where an administrator can define responsible people for each node. But I don't want to set the people on the leafs (the departments), I want to set some people in a higher node, e.g. district, country, ... And always when I reload these permissions for one people from database and want to show the tree with the pre-selected nodes, all selects are gone or will be not displayed as "selected".
UPDATE 2
I found a workaround for my problem, but perhaps you could find a better solution (IF you also think that this is a bug)
I used an own property "preselected" for each node, which will be then written to the data-object of the node and will not touched by the fixSelection3FromEndNodes() function. Then I wait for the "init" tree-event, which means the tree is loaded and rendered. Then I visit each node and read out the property "preselected" to call setSelected(true).
$('#tree').fancytree({
source: [
{ id: 1, key: 'A', title: 'A', children: [
{ id: 2, key: 'B', title: 'B', selected: true, preselected: true, children: [
{ id: 3, key: 'C', title: 'C' }
]}
]}
],
icon: false,
checkbox: true,
selectMode: 3,
init: function (event, data) {
data.tree.getRootNode().visit(function (node) {
if (node.data.preselected) node.setSelected(true);
});
}
});
I have updated the jsfiddle with the workaround:
https://jsfiddle.net/x36krqL6/2/