PDA

View Full Version : tree panel doesn't load on node expand



Mubin
11 Mar 2014, 6:21 AM
Hi guys,

Maybe somebody face such problem:

I cannot make tree load node on demand when expanding particular node.
I have a tree:

{
id:'ClassifyTreePanel',
region: 'west',
xtype: 'treepanel',
title: 'Classify Tree u',
rootVisible: true,
animate: false,
store:'ClassifyTree',
width: 400,
plugins: [{
ptype: 'treefilter'
, allowParentFolders: true
}],
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'trigger',
id:'txtSearchTreeField'
, triggerCls: 'x-form-clear-trigger'
, onTriggerClick: function () {
this.reset();
this.focus();
}
, listeners: {
//change: function (field, newVal) {
// var tree = field.up('treepanel');
// tree.filter(newVal,'Caption');
//}
//, buffer: 250
specialkey: function(field, e){
// e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
// e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
if (e.getKey() == e.ENTER) {
var s=Ext.getStore("ClassifyTree");
field.up('treepanel').getRootNode().collapse();
s.load({
params: {
searchString:field.getValue()
},
callback:function(){
field.up('treepanel').getRootNode().expand();
}
});
//var tree = field.up('treepanel');
//tree.filter(field.getValue(),'Caption');
}
}
}
}]
}],


columns: [
{xtype:'treecolumn',text:'Caption',dataIndex:'Caption', width:400}
]


}

treestore:

Ext.define('CCH3.store.ClassifyTree', {
extend: 'Ext.data.TreeStore',
requires : [
'CCH3.model.ClassifyTreeModel'
],
model: 'CCH3.model.ClassifyTreeModel',
defaultRootId:'0',
root: {
name: 'Tree',
expanded: true
},
storeId:"ClassifyTree",


proxy: {
type:'ajax',
url:'CCH-services.asmx/GetClassifyTreeNodes',


reader: {
type:'xml',
record:'>ClassifyTreeNode',
root:'children'


}
}
});
and model:

Ext.define('CCH3.model.ClassifyTreeModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'Caption', type: 'string' },
{name:'RefId',type:'int'}
]
});


initially assotiated web-service return only one level of tree:

<?xml version="1.0" encoding="utf-8"?><XMLResponse> <success>true</success> <data xsi:type="ClassifyTreeNode"> <leaf>0</leaf> <children> <ClassifyTreeNode> <leaf>0</leaf> <id>1729</id> <Caption>Node1</Caption> <RefId>1727</RefId> </ClassifyTreeNode> <ClassifyTreeNode> <leaf>0</leaf> <id>1730</id> <Caption>Node2</Caption> <RefId>1727</RefId> </ClassifyTreeNode> </children> <id>1727</id> <Caption>Nodes</Caption> <RefId xsi:nil="true" /> </data></XMLResponse>
It renders "plus" icons at the nodes showing possibility of expand and as I understood it should send ajax request to load children of expanding node. But it does nothing :( What's wrong with my code? Please help.

chamacs
11 Mar 2014, 11:10 AM
Did you try setting 'autoLoad:true' on the tree store?

Mubin
11 Mar 2014, 11:37 AM
It's not the case. Actually i found the solution, but forgot to write here: root property of proxy XML reader should not have value 'children'. It is reserved internally by proxy XMLReader. The same thing is working with JSON reader but not working with XML reader :) Is this a bug?:)

In anyway thanks for reply.