PDA

View Full Version : Dynamically adding nodes to the treepanel



url
29 Apr 2012, 10:10 PM
Hi,

I have a treepanel which is reading data from json file... The tree has 4 levels(heirachy). I want to select a node and add nodes dynamically under the selected node.

Here i'm facing two problems.

1) If the node is once expanded then i'm able to add child dynamically. If the node is not expanded then added node is not visible.

2) If the node already has childs then its accepting dynamically added nodes otherwise its not displaying any added nodes.

Any help would be appreciated..:-/

Thanx in Advance

vietits
30 Apr 2012, 12:09 AM
What does your code look like?

url
30 Apr 2012, 10:53 PM
updateTree: function(button, documentname, filename) {



var treegrid = Ext.ComponentQuery.query('abctreegrid')[0];//abctreegrid is treecolumn in treepanel


var fileda = treegrid.getSelectionModel().selected.items[0].data['a'];
var fieldb = treegrid.getSelectionModel().selected.items[0].data['b'];
//a,b are the fields i.e, remaining columns


var model = Ext.create('AM.model.mymodel', {
a:fileda,
b:filedb
});
if(!treegrid.getSelectionModel().selected.items[0].isExpanded())
{
var treeStore = treegrid.getStore();
treegrid.getSelectionModel().selected.items[0].insertChild(0, model);
}else
{
if (!Ext.isEmpty(filename)) {
treegrid.getSelectionModel().selected.items[0].insertChild(0, model);
}
}
button.up('window').close();
}

vietits
1 May 2012, 11:32 PM
It seems that the node you are inserting child nodes is a leaf not folder. So try to set it to folder. Example:


var treeStore = treegrid.getStore();
// treegrid.getSelectionModel().selected.items[0].insertChild(0, model);
var node = treegrid.getSelectionModel().getSelection()[0];
node.set('leaf', false); // <- force node to be a folder, not leaf
node.insertChild(0, model);

BTW: You should use component's public methods instead of accessing directly to component's private properties. It will make your code uncompatible to the future version of Ext.