PDA

View Full Version : Loading child nodes dynamically from different store/url than the parents Extjs 4.1



extdev22
21 Feb 2013, 7:02 PM
Hi,

I need help achieving this in Extjs 4.1:

1- Load parent nodes in Tree panel from URL "parentNodes/parentNodes.json"

parentNodes/parentNodes.json is:
[
{"id":1,"text":"ParentNode1","url":"","depth":"1","path":"ParentNode1/"},

{"id":2,"text":"ParentNode2","url":"","depth":"1","path":"ParentNode2/"}
]

2- Once user expands "ParentNode1" load its children from "ParentNode1/chiledNodes.json"

3- Once user expands "ParentNode2" load its children from "ParentNode2/chiledNodes.json"

Appreciate providing code example with the answer.

Thanks
Nameer,

Fredric Berling
22 Feb 2013, 7:34 AM
I would put a listener on the "beforeload" event on the TreeStore.

In there you can change the proxys url accordingly before the call is made.

extdev22
24 Feb 2013, 12:12 PM
Thanks Fredric, but in 'beforeload' event how do I know which parent node is expanding? so I can change the related URL to get the children of the current expanding parent node?

Can you please provide some code example?

Fredric Berling
25 Feb 2013, 7:14 AM
I was slightly wrong.. It the "beforeexpand" event you should be listening on .


listeners: {
beforeexpand: function (node) {
node.store.proxy.url = 'firstpart/' + node.getId() + '/secondpart'
}