I know I'm a little late to the party, but I found a solution to this as well. Hopefully it helps somebody.
First, you'll need an onSelect
handler for the tree (if you don't already have one). When a node is selected, mark it as selected, then expand it if possible. Here's mine:
onSelect: function(selected, node) {
if (selected === true) {
node.data.activateChildrenOnLoad = true; //Let the lazy children know
//node.expand(true) did not work for me, but it might for you
if (!node.isExpanded()) {
node.toggleExpand();
}
}
}
Next, you need to insert a bit of code into your onLazyRead
function. I handle all AJAX manually, so if you let dynatree handle it for you, you might need to change some things.
onLazyRead: function(node) {
getNodesFromServer(function(nodes) {
node.addChild({
selected: node.data.activateChildrenOnLoad,
activateChildrenOnLoad: node.data.activateChildrenOnLoad
});
if (node.data.activateChildrenOnLoad) {
var nodes = node.getChildren();
var last = nodes[nodes.length-1];
if (!last.isSelected()) {
last.toggleSelect();
}
if (!last.isExpanded()) {
last.toggleExpand();
}
}
});
}
And that's all there is to it. When you select (check) a node, it will recursively load, check and expand all of its lazy children.