PDA

View Full Version : stop lazy loading on ext tree panel & store



amitkumarchauhan
30 Apr 2012, 6:37 AM
I am using ext tree panel & ext tree store to render tree grid; i am providing json for all parents & respective children which can go till any level.Now when i expand any of the parent ...store fires request to load child data but i want to stop such lazy loading since my first load request itself is fetching complete data in hierarchy; how can i do that?

scottmartin
30 Apr 2012, 11:05 AM
How are you defining your tree? If you return the entire structure it should work as expected.

See TreePanel example:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.tree.Panel

Regards,
Scott.

nikolai.efimov
5 Feb 2013, 12:31 PM
I'm having the same problem. I return the full json with all the leafs on the first request.

Tree config:



{
xtype: 'treepanel',
store: Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url : 'app/php/getClusterTree.php',
reader: {
type: 'json',
root: 'data'
}
}
}),
rootVisible: false
}


JSON return from the server:



{
"success": "true",
"data": [{
"text": "ThisIsCluster1",
"children": [{
"children": [{
"text": "192.168.0.209",
"server_id": 1,
"leaf": "true"
},
{
"text": "192.168.0.208",
"server_id": 2,
"leaf": "true"
}],
"text": "Servers"
},
{
"children": [{
"text": "root",
"user_id": 1,
"leaf": "true"
}],
"text": "Users"
}]
},
... here two more entries ...
]
}


Screen shot:

41693

eternoendless
6 Mar 2013, 8:07 AM
I had the same problem, this other thread helped me to resolve it:

http://www.sencha.com/forum/showthread.php?163081-Tree-Store-how-using-nested-json-root-node

(look at post #5)

It seems that the object containing the tree within a JSON response needs to be called exactly the same as the 'children' property name. The only way of having it with a different name is by overriding getResponseData() in the reader so as to return the content of the tree within the response JSON.

In short, here's solution #1: (changing the object name from "data" to "children")


{
"success": "true",
"children": [{
"text": "ThisIsCluster1",
"children": [{
"children": [{
"text": "192.168.0.209",
"server_id": 1,
"leaf": "true"
},
{
"text": "192.168.0.208",
"server_id": 2,
"leaf": "true"
}],
"text": "Servers"
},
{
"children": [{
"text": "root",
"user_id": 1,
"leaf": "true"
}],
"text": "Users"
}]
},
... here two more entries ...
]
}


solution #2: (overriding getResponseData() in the reader)


store: {
...
reader: {
type: 'json',
getResponseData: function(response) {
var jsonData = Ext.JSON.decode(response.responseText,true);
return jsonData.data;
}
}
}