dojoselectiondijit.tree

How to disable multiple selection of nodes in dijit.Tree?


How to set selection mode single in dijit.Tree? What I mean by selection mode single is user should not be able to select multiple nodes by making use of shift key or ctrl key + mouse click on node.


Solution

  • The selection is handled by dijit/Tree::dndController, which defaults to dijit/tree/_dndSelector. There is a property singular in _dndSelector and its documentation states:

    singular: Boolean

    Allows selection of only one element, if true.

    Tree hasn't been tested in singular=true mode, unclear if it works.

    Anyway, it seems to work:

    var tree = new dijit.Tree({
        id: "tree1",
        model: model
    }).placeAt(win.body());
    
    tree.dndController.singular = true;
    

    Check it out at jsFiddle: http://jsfiddle.net/phusick/UxWUs/