Hierarchical mode behaviour

496 views
Skip to first unread message

Alessandro Malgaroli

unread,
Dec 9, 2009, 12:38:50 PM12/9/09
to dyna...@googlegroups.com
Hello everyone.

First, thanks for this fantastic piece of code.

I found a possible bug or - if not - a missing feature to the
hierarchical mode behaviour.
As far as I can tell, currently in selectMode 3, a parent node is
selected when all the children nodes are selected. If I deselect a
children node, the parent node (and the parent's parent, and so on) are
deselected and indicated via the "square checkbox" icon (nice visual
feature). But in the getSelectedNodes result, those partially selected
nodes aren't included. This is as expected, isn't it?

Anyway, the current behaviour implies that we should post-process the
keys that a user select in the tree adding the parents that he forgot
(the application that will receive the data needs data that way).
We tried to fiddle a bit with the onSelect handler, but it didn't work
as we expected as - of course - a "select" operation issued in the
onSelect handler (although on different nodes) creates all sorts of
undesirable side effects.

Any idea on how to solve this? Any possible idea of introducing another
selectMode (4) such as "multi-select with OR parent selection" (as I
could say that now the parent selection uses AND, as a parent is
selected only when ALL children are selected)? Or (better) an (optional)
argument to getSelectedNodes indicating that partially selected nodes
should be retrieved as well?

Thanks in advance

--
Alessandro Malgaroli
ISMB
mail: malg...@ismb.it
Corso Castelfidardo 30
Torino, ITALY

mar10

unread,
Dec 9, 2009, 3:55:46 PM12/9/09
to Discuss jquery.dynatree.js
Allessandro,

the dtnode object has an attribute 'hasSubSel', which should be true
for partly selected nodes.

Given this implementation
getSelectedNodes: function(stopOnParents) {
var nodeList = [];
this.tnRoot.visit(function(dtnode){
if( dtnode.bSelected ) {
nodeList.push(dtnode);
if( stopOnParents == true )
return false; // stop processing this branch
}
});
return nodeList;
},


you could try to implement a modified function

function getSelectedAndPartselNodes() {
var nodeList = [];
this.tnRoot.visit(function(dtnode){
if( dtnode.bSelected || dtnode.hasSubSel) {
nodeList.push(dtnode);
}
});
return nodeList;
}

(I havent tried out the code above, so it may not work as is).
Hope this helps
Martin
> mail: malgar...@ismb.it

jsanfe...@gmail.com

unread,
Apr 24, 2013, 6:48:32 AM4/24/13
to dyna...@googlegroups.com
It worked for me! Thank you very much mar10!
Reply all
Reply to author
Forward
0 new messages