How to make an item active(selected) by default while using Treelist(Ext.list.Tree) in Extjs 6?

1.6k views Asked by At

I want to make the first item from a tree list be selected by default. I am working on extjs 6. Any help will be greatly appreciated.

2

There are 2 answers

4
scebotari66 On BEST ANSWER

Try this:

listeners: {
    element: 'element',
    painted: function (treelistEl) {
        var treelist = treelistEl.component;
        treelist.setSelection(treelist.getStore().getRoot().firstChild);
    }
}

0
Johan Van de Merwe On

This worked for me:

In the listeners of the treelist:

painted: function (treelist) {
    var c = treelist.component;
    var model = c.getStore().getAt(0);
    c.setSelection(model);
}

That will trigger the selectionchange event on that same treelist.