PDA

View Full Version : How to expand particular node in tree panel - Extjs 4



renganathan
8 Dec 2011, 10:11 PM
hi all,

i would like to know , How to expand the particular node in the tree panel?

Please share ur experience.

skirtle
8 Dec 2011, 11:51 PM
Nodes have an expand method:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.NodeInterface-method-expand

A node can also be created expanded:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.NodeInterface-cfg-expanded

Trees have an expandPath method:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.tree.Panel-method-expandPath

The format used by expandPath is compatible with getPath:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.NodeInterface-method-getPath

renganathan
9 Dec 2011, 12:34 AM
Hi,

can u give some working example?

skirtle
9 Dec 2011, 12:47 AM
You haven't given enough information on what you're trying to do for us to provide you with an example.

renganathan
9 Dec 2011, 1:18 AM
var invTreeStore = Ext.create('Ext.data.TreeStore',
{
proxy : {
type : 'ajax',
url : 'lab_tree.class.php'//'get_tree_nodes.php'
},
root : {
text : 'Labs',
id : '0|getLabs',
expanded : true
},
folderSort : true,
sorters : [{
property : 'text',
direction : 'ASC'
}]
});



var labTree = Ext.create('Ext.tree.Panel',
{
//title : 'labTree',
renderTo : Ext.getBody(),
id : 'labTree',
lines : true,
autoHeight : true,
containerScroll : true,
autoScroll : true,
frame :true,
iconCls : 'icon-basket',
style : 'padding-bottom: 5px',
store : invTreeStore,//powerTreeStore,
rootVisible : false,
//collapsed : true,
listeners :
{
itemclick : function clickListener (view, rec, item, index, eventObj)
{

labhidden.setValue(rec.raw.chain['lab']);

aislehidden.setValue(rec.raw.chain['aisle']);

aislelochidden.setValue(rec.raw.chain['aisle_location']);

deviceStore.load();


}

},

dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Expand All',
handler: function(){
labTree.expandAll();
}
}, {
text: 'Collapse All',
handler: function(){
labTree.collapseAll();
}
}]
}]
});




This is my code for tree panel. i want to expand one particular node by default.

Pramma
26 Sep 2012, 1:52 AM
If you know the Id of the node you can do tree.expandPath(store.getNodeById(id).getPath())