PDA

View Full Version : reload tree panel on ajax call



nityajs
12 Aug 2009, 10:52 AM
Hi All,

I have grid and tree panel. When a row is clicked on the grid, an ajax request is made and json data comes from server which is used in tree panel. I am unable to reload the tree panel to display the new leafs.This tree is used as an item in formpanel.

Here is my code
----------------


var mytree= new Ext.tree.AsyncTreeNode({
children: [{
text: 'Parent',
expanded: true,
children: 'dynaChilds'
}]
})

// Create the "SampleTreePanel" pre-configured class
SampleTreePanel = Ext.extend(Ext.tree.TreePanel, {
// title: 'Deal Header',
width: 200,
height: 400,
loader: new Ext.tree.TreeLoader(),
rootVisible: false,
border: false,
initComponent: function(){
Ext.apply(this, {
root: mytree
})
SampleTreePanel.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('tree_panel', SampleTreePanel);
// Instantiate the tree panel, then attach an event listener..
var tree = new SampleTreePanel();
tree.on('click', function(node, e){
// debugger;
Ext.Msg.alert("",'clicked: '+ node.text);
}, this);


Here is my grid code:
---------------------

var resultsGrid = new Ext.grid.GridPanel({
id:'searchResultsGrid',
store: ds,
cm: colModel,
selModel: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: {
rowselect: function(sm, row, rec) {
myForm.getForm().loadRecord(rec);
Ext.Ajax.request ( {
url:contextPath (http://extjs.com/forum/contextPath) + "/test?action=getleafs",
params: "id=" + Ext.get('studentId').getValue(),
success: function ( response ) {
x = response.responseText;
Ext.Msg.alert('reponse--->',x);

},
failure: function ( ) { console.log ( 'failure' ) ; } ,
} ) ;
}
}
}),
viewConfig: {
forceFit:true
},
autoExpandColumn: 'Type',
height: 300,
title:'Search Results',
border: true,
listeners: {
render: function(g) {
//g.getSelectionModel().selectRow(0);
},
delay: 10 // Allow rows to be rendered.
}

});


Here is the response from the server:
-------------------------------------
{dynaChilds:[{text:'122',leaf: true},{text:'123',leaf: true},]}


Can any one please tell me how to reload the tree panel.
I tried below two after I alert the ajax response but no luck.
tree.getLoader().reload()
tree.setRootNode(mytree).

herry
28 Sep 2009, 1:50 AM
tree.getRootNode().reload();

if you want to reset the dataUrl,maybe you can do this:
Ext.apply(ree.getLoader(),
{
dataUrl:'someNewUrl'
});