PDA

View Full Version : TreePanel / TreeStore with proxy



KostasP
6 Mar 2012, 9:25 PM
I have a treepanel using a treestore with an ajax proxy to an php file generating some json code. I want to dynamically reload my tree. So I call

tree.getStore().load({url: 'jsonprovider.php?param=' + var });

to reload my store-tree with no success an when i monitored my network activity I noticed that a big mumber of request are send to the php file with the DELETE method. So i guess it sends a request for every node destroyed or something. Is there any way to define my store/tree so that it only uses the proxy to read the new tree and never send other requests?


Ext.define('mytreestore',{
extend:'Ext.data.TreeStore',
autoLoad: false,
noCache: false,
autoSync: false,
proxy: {
actionMethods: {
create: 'GET',
destroy: 'DELETE',
read: 'GET',
update: 'GET'
},
type: 'ajax',
url: 'jsonprovider.php'
}
});

chramer
6 Mar 2012, 11:18 PM
this is a known bug (http://www.sencha.com/forum/showthread.php?151211-Reloading-TreeStore-adds-all-records-to-store-getRemovedRecords&p=661157#post661157)!
here is a workaround..
override the load method of the treestore this way :

//FIXME on load removes all records
load : function(options) {

options = options || {};
options.params = options.params || {};

var me = this,
node = options.node || me.tree.getRootNode(),
root;

// If there is not a node it means the user hasnt defined a rootnode yet. In this case lets just
// create one for them.
if (!node) {
node = me.setRootNode({
expanded: true
});
}

if (me.clearOnLoad) {
//BUG
//node.removeAll(true);
node.removeAll(false);
}

Ext.applyIf(options, {
node: node
});
options.params[me.nodeParam] = node ? node.getId() : 'root';

if (node) {
node.set('loading', true);
}

return me.callParent([options]);
}

KostasP
7 Mar 2012, 5:35 PM
Thx a lot!