Extjs treepanel store.load() problems

T1000 picture T1000 · Jul 9, 2013 · Viewed 7.3k times · Source

Hello I'm using Ext version: 4.2.0.663
I'm trying to reload the data in my treepanel but I have two problems:

*1st problem is I can't disable the autoLoad
---- 1st is fixed - you need to set the store.root.expanded to false ----

*2nd problem is that when I'm trying to make "treeview.store.load();" it reloads the data but the children are missing and when I try to click to collapse the parent brings out this error :
Uncaught TypeError: Cannot call method 'insertSibling' of null
ext-all-dev.js:158815

This is how I create the treepanel :

{
xtype:'treepanel',
region:'west',
width:200,
dockedItems:[
    {
        xtype: 'toolbar',
        dock: 'top',
        id: 'msgToolbar',
        style: 'font-weight:bold',
        items: [
            {
                xtype: 'button',
                text:'Add new tab',
                iconCls:'button-add'
            }
        ]
    }
],
store: Ext.create('Ext.data.TreeStore', {
    autoLoad: false,
    proxy: {
        type: 'ajax',
        url: 'path to controller',
        extraParams : {
            launch:'functionName'
        }
    },
    root: {
        text: 'Tabs',
        expanded: true
    },
    folderSort: true,
    sorters: [{
        property: 'text',
        direction: 'ASC'
    }]
})

}

When I reload the page the treepanel is automatically load the data (even autoLoad:false) and everything is ok but when I try to make treepanel.store().load() the second bug occurs.
In both cases the data that is returned from php is absolutely the same (also the header - I mean 2 identical requests)

Answer

T1000 picture T1000 · Jul 10, 2013

Before reloading the child nodes it needs to make collapse on the root node, so at the moment I'm doing this and everything is ok:

treepanel.collapseAll(function(){
    treepanel.store.proxy.extraParams.record_id = record.get('record_id');
    treepanel.store.load({
        callback: function(records, operation, success) {
            treepanel.expandAll();
        }                               
    });
});

If you don't want to see the "expand/collapse" animation you can set enableAnimations:false on the treepanel.