1

I have tree panel:

        xtype : 'treepanel',
        itemId : 'field-tree-command-metas',
        region : 'center',
        hideHeaders : true,
        rootVisible : false,
        emptyText : 'No Commands Available',
        deferEmptyText : true,
        bufferedRenderer : false,
        reference : 'treeCommandMetas',
        bind : {
            selection : '{bindSelection}'
        },
        listeners : {
            boxready : function() {
                var treeView = this.getView();
                treeView.refresh();
            }
        },
        columns : [ {
            xtype : 'noicontreecolumn',
            dataIndex : 'name',
            flex : 1,
            nodeIconsProvider : function(record) {
                if (record.isLeaf()) {
                    return [ '<i class="' + Glyphs.getIconClass('square-o', 'size-14px') + '"></i>' ];
                }

                if (record.isExpanded()) {
                    return [ '<i class="' + Glyphs.getIconClass('folder-open-o', 'fa-lg') + '"></i>' ];
                }

                return [ '<i class="' + Glyphs.getIconClass('folder-o', 'fa-lg') + '"></i>' ];
            }
        } ],
        displayField : 'name',
        store : 'Plugin.scheduler.store.CommandMetaStore'

On form loaded in this tree a record is selected. Is it possible to disable other selections? I mean that if something in tree is selected, user cannot change selection. Tried 'disableSelection:true' but it disables all selections, I would like selection made by default visible.

rageit
  • 3,513
  • 1
  • 26
  • 38
Edgar
  • 1,120
  • 4
  • 28
  • 53

2 Answers2

1

You can use setLocked to disable other selections:

treepanel.getSelectionModel().setLocked(true);

If you want to enable selections you can just use the reverse:

treepanel.getSelectionModel().setLocked(false);

I have an example here using ExtJS 4.2.1: https://fiddle.sencha.com/#fiddle/nqf

Zero Cool
  • 1,866
  • 4
  • 19
  • 28
0

Implement the beforeselect listener and make it return false to disable the mouse click selection:

listeners:{
    boxready : your boxready function,
    beforeselect :function(){
        return false;
    }
}

Then whenever you click any row of the tree,the selection won't change.

here's the api explanation:

beforeselect( this, record, index, eOpts )
Fired before a record is selected. If any listener returns false, the selection is cancelled. Please refer api doc here.

happyyangyuan
  • 179
  • 3
  • 14