View Full Version : Loading a TreeStore with unstructured data (ID & ParentID)

2 Mar 2012, 4:52 AM

I've an application server that provides a hierarchical group structure as a simple list. The list will have an ID and a ParentID for each entry. I would like to load this data into a TreeView with correct childs.

Is there any way to change the received data inside the store (so its organised in a tree structure with objects) after receiving the data via Ajax? I cannot find the right starting point. Can you give me a hint?

2 Mar 2012, 6:00 AM
One solution as below:
Basing on your data in flat list, construct the hierarchical treeData that can be loaded into your treeStore.
Use <tree>.getRootNode().appendChild(treeData) to add your data to your root node of treeStore.
The other solution is create your own data reader by extending the existing one (ex Ext.data.reader.Json), implement getResponseData() method to convert your flat data into hierarchical data. Then use this reader for your proxy reader.

2 Mar 2012, 6:14 AM

I'd like to have a special store, that can transform the flat data into a tree. So I'm currently trying to transform the data one the fly.

Ext.define('Tequiol.data.FlatTreeStore', {
extend: 'Ext.data.TreeStore',

loadRecords: function(records, options) {

I don't know which function oof the tree gets the data from the reader and where to transform it. Where is the starting point to change the data format inside my class? I'm currently researching the source code but cannot find anything that seems to be useful.

2 Mar 2012, 6:37 AM
One way is create your own reader to transform flat data to a tree as I suggested in my previous post. This way you can transform data on the fly.

The other solution is extending Ext.data.TreeStore as you do and implemnet onProxyLoad()method. However, I am not sure with this solution.

2 Mar 2012, 7:23 AM

the readers readRecords function was the starting point i was looking for. I'm now processing the data before calling this.callParent. I've derived it from Ext.data.reader.Json. Thanks for your assistance.