In Dynatree there was an "unselectable" property that prevented selection:
{"key":"4","title":"Sub-item 4.4 (unselectable)", "unselectable":true }
The demo page shows an example that allows these nodes to be clicked:
http://wwwendt.de/tech/fancytree/demo/
I modified the selectable demo to illustrate this more cleanly. In the demo below clicking the parent folder in selectMode 3 resulted in the unselectable node being selected.
<script type="text/javascript">
var treeData = [
{title: "My Folder with Unselectable inside", key: "id4", expand: true,
children: [
{title: "Sub-item 4.3 empty"},
{title: "Sub-item 4.4 (unselectable)", unselectable: true },
{title: "Sub-item 4.5 empty", unselectable: true }
]
},
{title: "item (unselectable)", unselectable: true }
];
$(function(){
// --- Initialize sample trees
$("#tree1").fancytree({
// extensions: ["select"],
checkbox: true,
selectMode: 1,
source: treeData,
activate: function(e, data) {
$("#echoActive1").text(data.node.title);
},
select: function(e, data) {
// Display list of selected nodes
var s = data.tree.getSelectedNodes().join(", ");
$("#echoSelection1").text(s);
},
dblclick: function(e, data) {
data.node.toggleSelected();
},
keydown: function(e, data) {
if( e.which === 32 ) {
data.node.toggleSelected();
return false;
}
}
});
$("#tree2").fancytree({
// extensions: ["select"],
checkbox: true,
selectMode: 2,
source: treeData,
select: function(e, data) {
// Display list of selected nodes
var selNodes = data.tree.getSelectedNodes();
// convert to title/key array
var selKeys = $.map(selNodes, function(node){
return "[" + node.key + "]: '" + node.title + "'";
});
$("#echoSelection2").text(selKeys.join(", "));
},
click: function(e, data) {
// We should not toggle, if target was "checkbox", because this
// would result in double-toggle (i.e. no toggle)
if( $.ui.fancytree.getEventTargetType(e) == "title" ){
data.node.toggleSelected();
}
},
keydown: function(e, data) {
if( e.which === 32 ) {
data.node.toggleSelected();
return false;
}
},
// The following options are only required, if we have more than one tree on one page:
cookieId: "fancytree-Cb2",
idPrefix: "fancytree-Cb2-"
});
$("#tree3").fancytree({
// extensions: ["select"],
checkbox: true,
selectMode: 3,
source: treeData,
select: function(e, data) {
// Get a list of all selected nodes, and convert to a key array:
var selKeys = $.map(data.tree.getSelectedNodes(), function(node){
return node.key;
});
$("#echoSelection3").text(selKeys.join(", "));
// Get a list of all selected TOP nodes
var selRootNodes = data.tree.getSelectedNodes(true);
// ... and convert to a key array:
var selRootKeys = $.map(selRootNodes, function(node){
return node.key;
});
$("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
$("#echoSelectionRoots3").text(selRootNodes.join(", "));
},
dblclick: function(e, data) {
data.node.toggleSelected();
},
keydown: function(e, data) {
if( e.which === 32 ) {
data.node.toggleSelected();
return false;
}
},
// The following options are only required, if we have more than one tree on one page:
// initId: "treeData",
cookieId: "fancytree-Cb3",
idPrefix: "fancytree-Cb3-"
});
$("#tree4").fancytree({
// extensions: ["select"],
checkbox: false,
selectMode: 2,
source: treeData,
beforeSelect: function(e, data) {
if( data.node.folder ){
return false;
}
},
select: function(e, data) {
// Display list of selected nodes
var selNodes = data.tree.getSelectedNodes();
// convert to title/key array
var selKeys = $.map(selNodes, function(node){
return "[" + node.key + "]: '" + node.title + "'";
});
$("#echoSelection4").text(selKeys.join(", "));
},
click: function(e, data) {
if( ! data.node.folder ){
data.node.toggleSelected();
}
},
dblclick: function(e, data) {
data.node.toggleExpanded();
},
keydown: function(e, data) {
if( e.which === 32 ) {
data.node.toggleSelected();
return false;
}
},
// The following options are only required, if we have more than one tree on one page:
// initId: "treeData",
cookieId: "fancytree-Cb4",
idPrefix: "fancytree-Cb4-"
});
$("#btnToggleSelect").click(function(){
$("#tree2").fancytree("getRootNode").visit(function(node){
node.toggleSelected();
});
return false;
});
$("#btnDeselectAll").click(function(){
$("#tree2").fancytree("getTree").visit(function(node){
node.setSelected(false);
});
return false;
});
$("#btnSelectAll").click(function(){
$("#tree2").fancytree("getTree").visit(function(node){
node.setSelected(true);
});
return false;
});
});
</script>
Example: Selection and checkbox
<!-- Tree #1 -->
<p class="description">
This tree has <b>checkoxes and selectMode 1 (single-selection)</b> enabled.<br>
A double-click handler selects a <i>document</i> node (not folders).<br>
A keydown handler selects on [space].<br>
The <code>checkbox</code> icons are replaced by radio buttons by adding
the 'fancytree-radio' class to the container.<br>
Note: the initialization data contains multiple selected nodes. This is
considered bad input data and <b>not</b> fixed automatically (only on
the first click).
</p>
<div>
<label for="skinswitcher">Skin:</label> <select id="skinswitcher"></select>
</div>
<div id="tree1" class="fancytree-radio">
</div>
<div>Active node: <span id="echoActive1">-</span></div>
<div>Selection: <span id="echoSelection1">-</span></div>
<!-- Tree #2 -->
<p class="description">
This tree has <b>selectMode 2 (multi-selection)</b> enabled.<br>
A single-click handler selects the node.<br>
A keydown handler selects on [space].
</p>
<p>
<a href="#" id="btnSelectAll">Select all</a> -
<a href="#" id="btnDeselectAll">Deselect all</a> -
<a href="#" id="btnToggleSelect">Toggle select</a>
</p>
<div id="tree2"></div>
<div>Selected keys: <span id="echoSelection2">-</span></div>
<!-- Tree #3 -->
<p class="description">
This tree has <b>checkoxes and selectMode 3 (hierarchical multi-selection)</b> enabled.<br>
A double-click handler selects the node.<br>
A keydown handler selects on [space].
</p>
<div id="tree3"></div>
<div>Selected keys: <span id="echoSelection3">-</span></div>
<div>Selected root keys: <span id="echoSelectionRootKeys3">-</span></div>
<div>Selected root nodes: <span id="echoSelectionRoots3">-</span></div>
<!-- Tree #4 -->
<p class="description">
This tree has selectMode 2 (multi-selection) enabled, but <b>no checkboxes</b>.<br>
A single-click handler selects the node.<br>
A keydown handler selects on [space].<br>
A double-click handler expands documents.<br>
A onQuerySelect handler prevents selection of folders.
</p>
<div id="tree4"></div>
<div>Selected keys: <span id="echoSelection4">-</span></div>
<!-- Start_Exclude: This block is not part of the sample code -->
<hr>
<p class="sample-links no_code">
<a class="hideInsideFS" href="https://github.com/mar10/fancytree">jquery.fancytree.js project home</a>
<a class="hideOutsideFS" href="#">Link to this page</a>
<a class="hideInsideFS" href="index.html">Example Browser</a>
<a href="#" id="codeExample">View source code</a>
</p>
<pre id="sourceCode" class="prettyprint" style="display:none"></pre>
<!-- End_Exclude -->