PDA

View Full Version : Tree Panel data



varunjyoti
3 Jul 2012, 3:34 AM
I have a Tree Panel


Ext.define('DG.view.reports.AttributeFilter', {
extend: 'Ext.tree.Panel',
alias: 'widget.AttributeFilter',
store:'Attributes'
});


and a TreeStore



Ext.define('DG.store.Attributes', {
extend: 'Ext.data.TreeStore',
model: 'DG.model.Attribute',
listeners: {
append: function( thisNode, newChildNode, index, eOpts ) {
if( !newChildNode.isRoot() ) {
newChildNode.set('leaf', true);
newChildNode.set('checked', true);
newChildNode.set('text', newChildNode.get('attributeName'));
}
}
} ,
proxy: {
type: 'ajax',
url: 'http://localhost:8080/DgDashboard/app/Attributes.json',
reader: {
type: 'json',
root: 'result',
successProperty: 'success'
}
},

});



The JSON retruned is



{
"success":true,
"result":[
{
"attributeId":"1",
"attributeType":"Application",
"attributeName":"Application1",
"attributeDesc":"Application"
},
{
"attributeId":"2",
"attributeType":"LOB",
"attributeName":"LOB1",
"attributeDesc":"LOB"
},
{
"attributeId":"3",
"attributeType":"LOB",
"attributeName":"LOB2",
"attributeDesc":"LOB"
}
]
}

Currently the tree panel is showing data as


Root
-->Application1
-->LOB1
-->LOB2

I want to group the data based on "attributeType". So the data should be displayed as


Root
-->Application
-->Application1
-->LOB
-->LOB1
-->LOB2

Is there an inbuilt way to do it easily, or i have to write a logic to add nodes one by one based on their type etc.

grgur
3 Jul 2012, 4:12 AM
There are quite a few methodologies for storing tree-like structures. Ext.data.TreeStore follows parent -> children methodology.

Frankly, you have two ways out:
1. Use the built in store and adopt your data model to it's principles
2. Build your own data store to accommodate the needs

varunjyoti
3 Jul 2012, 4:24 AM
grgur,

can you explain your views with an example based on my problem please?