PDA

View Full Version : treestore not loading data



glafrance
14 Sep 2012, 9:47 AM
I have a popup window that has a treepanel that uses a tree store to load data. I had thought that because autoLoad is true, the treestore would load the data when the window and its treepanel are rendered, but no ajax call is being made.


{
xtype: "treepanel",
flex: 1,
id: "switchCompanyGrid",
margin: '0 7 0 7',
store: {
type: 'treestore',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/myservice/rest/api/ipass/300/svc/TTBB/Company/500'
}
},
columns: [{
xtype: 'treecolumn',
text: 'Company Name',
flex: 2,
dataIndex: 'name'
},{
text: 'ID',
flex: 1,
dataIndex: 'id'
},{
text: 'Action',
flex: 1
}]
}

scottmartin
14 Sep 2012, 10:16 AM
Try loading your store first.

Scott.

glafrance
14 Sep 2012, 10:23 AM
I'm somewhat new to ExtJS, so I'm not sure what you mean by try to load your store first.

Do you mean that rather than having the store as a config in the tree panel I should create a var for the treestore so it gets loaded?

But I'm still wondering, should my code in fact work as is? I thought that when autoLoad is true, then when the component is rendered the store loads. Is that not true?

scottmartin
14 Sep 2012, 10:55 AM
The issue is that ajax takes time to return .. and your code has moved on..

Scott.

vietits
14 Sep 2012, 3:44 PM
Try to fix your code like below. Also, you need to config fields or model for your store.


{
xtype: "treepanel",
flex: 1,
id: "switchCompanyGrid",
margin: '0 7 0 7',
store: {
// type: 'treestore', <- no need, TreePanel will automatically create Ext.data.TreeStore
root: {}, // <- force treestore to setRootNode then it will load root data
autoLoad: true,
proxy: {
type: 'ajax',
url: '/myservice/rest/api/ipass/300/svc/TTBB/Company/500'
}
},
columns: [{
xtype: 'treecolumn',
text: 'Company Name',
flex: 2,
dataIndex: 'name'
},{
text: 'ID',
flex: 1,
dataIndex: 'id'
},{
text: 'Action',
flex: 1
}]
}