javascriptextjsselectiontreepanel

EXTJS tree panel disable selection change


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.


Solution

  • 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