ExtJs Tree loading sequence
<p>Good day.</p>

<p>I am writing a tree control with <strong>Ext.tree.Panel</strong>, which loads its configuration from external .json file, while data  is being loaded as .json from the server.</p>

<p>So, I've got the view like this:</p>

<pre><code>Ext.define('App.tree.TreeView', {
    extend: 'Ext.tree.Panel',
    ...
    initFilters: function(cfg) {
        /*several this.store.addFilter() based on cfg*/
    },   
    initComponent: function () {
        var me = this;
        me.cfg = getSomeCfgFromSomewhere();
        me.initFilters(me.cfg);
    }    
});
</code></pre>

<p>The store:</p>

<pre><code>Ext.define('Site.widgets.tree.TreeStore', {
    extend: 'Ext.data.TreeStore',
    ...
    proxy: { 
        type: App.cfg.proxy, 
        reader: { type: 'json', rootProperty: 'data.children' }, 
        format: App.cfg.proxy.urlEnd, 
        url: App.cfg.treeRoot, 
        noCache: false
    }
    lazyFill: true,

    rootVisible: true,
    root: {
        full_path: '/', /*set as idProperty in model*/
        'display-name': 'root',
        expanded: true
    },
});
</code></pre>

<p>The problem is: my root is explicitly set in the store, which loads its contents because of <strong>expanded: true</strong>. But then only these contents are shown in the tree, without the root itself. When filtering is removed, the tre is loaded OK.</p>

<p>Possible reason: from debugging of Sencha code in ext-all-debug.js: view's <strong>initComponent</strong> is called before the store starts loading the data, therefore it adds filters before the data is loaded, when the root is still empty, and then calls </p>

<pre><code>onNodeFilter: function(root, childNodes) {
    var me = this,
        data = me.getData(),
        toAdd = [];
    if (me.getRootVisible()) {
        if (childNodes.length) {
            toAdd.push(root);
        } else {
            root.set('visible', false, me._silentOptions);
        }
    }
    ...
}
</code></pre>

<p>, i.e. the root is set invisible because it is still empty, and only then root's children are loaded.</p>

<p>The question is: is there an initial design mistake in my filters initialisation, and how can I fix it?</p>