The Dijit Tree component lets you select multiple options by default and there is no easy way to turn that off, or atleast none that I could find. Ideally, this should be a configurable property, byt sadly, that’s not the case.
However, there is a “singular” property on the _dndSelector that would let us disable multi-select.
The easiest way is to just extend the Tree class and set singular: true :-
[js]define([
‘dojo/_base/declare’,
‘dijit/Tree’
], function (
declare,
Tree
) {
return declare(‘SingleSelectionTree’, Tree, {
singular: true,
/*add "singular" property to the default dndParams
as we want to be able to disable
multi selection of tree nodes */
dndParams: [
"singular",
"onDndDrop",
"itemCreator",
"onDndCancel",
"checkAcceptance",
"checkItemAcceptance",
"dragThreshold",
"betweenThreshold"
]
});
})[/js]
Once that is done, you can use this new Class like below :-
[js highlight=”8″]define([
‘SingleSelectionTree’,
‘dijit/tree/_dndSelector’,
], function (
SingleSelectionTree,
_dndSelector) {
var myTree = new SingleSelectionTree({
dndController: _dndSelector,
……
other config params
…….
});
})[/js]
Hope this little tip helps someone out 🙂