Results 1 to 4 of 4

Thread: How to make items in a Tree unselectable

  1. #1
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Zurich, Switzerland
    Posts
    25

    Default How to make items in a Tree unselectable

    I have a Tree object which contains a few objects of my own class (MenuItem) which has a few simple attributes (mostly Strings). When specific conditions are met, I would like to make some of the items in the Tree are unselectable, so that the user cannot select them in the tree.

    Here is how my tree is defined:
    Code:
            Tree<MenuItem, ?> menuTree = getView().getMenu();
    
            TreeSelectionModel<MenuItem> selectionModel = menuTree.getSelectionModel();
            selectionModel.addSelectionHandler(new SelectionHandler<MenuItem>() {
    
                @Override
                public void onSelection(SelectionEvent<MenuItem> event) {
                    MenuItem menu = event.getSelectedItem();
                    
                     // some business logic code
                    
                }
            });
    Is there any way how to do that? Do I need to have a custom selection model for my Tree?

  2. #2
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737

    Default

    Add a BeforeSelectionHandler, check the item and see if you want it to be selected, and if no, cancel the event. Doing so will stop the actual SelectionEvent and selection behavior from occurring.

  3. #3
    Sencha Premium Member
    Join Date
    Oct 2012
    Location
    Zurich, Switzerland
    Posts
    25

    Default

    Thank you Colin for a good hint.

    Is there any way to disable the whole tree (with its all items)? Calling setEnabled(false) has no effects. When the tree is in a container which is then disabled, it does not also bring any changes.

  4. #4
    Sencha Premium Member feelinforyou's Avatar
    Join Date
    Dec 2012
    Posts
    100

    Default

    Code:
    tree.getSelectionModel().setLocked(true);

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •