PDA

View Full Version : Tree



bauchinj
21 Dec 2009, 5:52 AM
Hello!

Given is a asynchronous tree:

User
- admin
- stefan
- phil
Groups
- sa
- su

so on... Now I'd like to add a new user, after adding, the tree should be reloaded:

Ext.getCmp('tree').root.reload();

After reloading, the node 'User' should be expanded and the new user should be selected!

In the meantime, I already tested some variants - but with no success as you can see!
I can work with the id of the node, as well as with the path of it (best). But everything I have tried failed.... After the reload, it's like no node (user & group) is exitsting. Although if I do expandAll() on root....


Hope somebody can help!

Fredric Berling
21 Dec 2009, 5:56 AM
Could you post some code on that? .. Where are your listeners wich acts on the nodes?

Since you are acting on a asyncron tree you must attach listeners on the right place (on load), to be sure you actually have a tree and nods to act on.

bauchinj
21 Dec 2009, 8:31 AM
[solved]

Hi!


Thank you for your request - I have solved the problem now:

root.findChild(...).reload();

bauchinj
21 Dec 2009, 10:44 PM
Now I've got the following problem:

If User has no Childs, I have defined it as leaf. So If I would reload this node (=leaf), I get the message, that reload is not a function. => I think, reload isn't be able to use for leafs.

BUT I don't want to reload the whole root (or I'm able to recognize, if groups is expanded)!


Ext.getCmp('tree').root.findChild("id","root/user").reload();

bauchinj
21 Dec 2009, 11:02 PM
Here's my tree:



new Ext.tree.TreePanel({
id : 'tree',
loader : new Ext.tree.TreeLoader({
dataUrl : 'tree.php',
preloadChilderen : true
}),
rootVisible : false,
lines : false,
autoScroll : true,
root : new Ext.tree.AsyncTreeNode({
text : 'root',
id : 'root'
}),
listeners:
{ click: function(node, e)
{ var tmp_node = node.id;
var arr_node = tmp_node.split('/');
switch(arr_node.length){
case 2:
switch(arr_node[1]){
case 'user':
//some function: new user
break;

case 'groups':
//some function: new group
break;
}
break;

case 3:
switch(arr_node[1]){
case 'user':
//some function: edit user
break;

case 'groups':
//some function: edit group
break;
}
break;
}
}
}
})

bauchinj
21 Dec 2009, 11:27 PM
Here is the JSON I get from php when loading tree first (user exist, but no group):
[{"text":"user","id":"root\/user","leaf":false,"cls":"users","iconCls":"users"},
{"text":"There is no group!","id":"root\/groups","leaf":true,"cls":"groups","iconCls":"groups"}]

Next, I expand the node user - I get following JSON:

[{"text":"tester","id":"root\/user\/tester","leaf":true,"cls":"user","iconCls":"user"}]


NOW I want just to update JUST the node 'user' and reload it! But I don't know, how!!!
If I just reload the node, the text of the node don't change, but it should - it also should get a leaf. If I reload the root, also groups is collapsed - I don't know, but if I'd like to expand it with ....root.findChild....expand(), I get a error:

....expand is not a function :-?

It's like no node with the id 'root/group' is existing, but it IS!