PDA

View Full Version : Ext.tree.Panel with local data



csanchezr85
29 Apr 2012, 11:40 PM
Hello,

I have a problem with this component. I want to create a Ext.tree.Panel from local data, but I'm having some difficulties. All the web samples load data into an Ext.data.TreeStore with a 'ajax' proxy. This isn't valid for me because I have a specific class to communicate to server, and this class must pass the data to the TreeStore or to the Ext.tree.Panel directly.

I've seen some examples that use an Ext.Tree.TreeLoader() in 'loader' property of the panel. But it seems to be a deprecated object, because I'm working with 4.1 version and this library doesn't exists. Because of this, I think that these examples are too old.

I also found a thread where someone give an advice to use an Ext.data.Store with a 'memory' proxy type. In theory, this store have a 'data' property where I could specify the data I want, but this didn't work for me.

How can I render a tree with local data?

Thanks.

vietits
30 Apr 2012, 12:01 AM
FYI


Ext.onReady(function(){

var store = Ext.create('Ext.data.TreeStore', {
fields: ['text'],
root: {
text: 'root',
children: [{
text: 'node 1',
children: [{
text: 'node 1.1',
leaf: true
},{
text: 'node 1.2',
leaf: true
}]
},{
text: 'node 2',
children: [{
text: 'node 2.1',
children: [{
text: 'node 2.1.1',
leaf: true
},{
text: 'node 2.1.2',
leaf: true
}]
},{
text: 'node 2.2',
leaf: true
}]
}]
}
});


Ext.create('Ext.tree.Panel', {
renderTo: Ext.getBody(),
width: 400,
height: 400,
store: store
});
});

csanchezr85
30 Apr 2012, 12:16 AM
Thanks!! That's just what I needed. I had been looking for complex solutions and I couldn't see the easy way to make this work.

Thank you.