PDA

View Full Version : nested data and drag&drop tree



mario60
3 Oct 2011, 12:00 AM
Hello

very happy if you may give some advise and answers.
Please see:
http://stackoverflow.com/questions/7632363/extjs-4-how-do-i-show-nested-data-into-a-tree

Thanks a lot
mario ~o)~o)~o)

tvanzoelen
3 Oct 2011, 11:31 PM
I don't understand, earlier there where questions about this.

Indeed, it is in the docs: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader. Following the docs the view should work using multiple models, but that isn't the case for the tree because you can only have one model in the tree or in the reader you can only define one rootnode.

Conclusion: the situation in the docs is much more advanced than reality is.

Or maybe this only works for the (Tree)Grid

mario60
4 Oct 2011, 11:50 AM
*****************
I have second thoughts. The trick to use a unique string 'children' does not seem so good.
Let me consider a very simple my_file.json:


{
"users": [
{
"id": 12,
"name": "Ed2",
"orders": []
},
{
"id": 123,
"name": "Ed",
"orders": [
{
"id": 50,
"info" : "hello",
"name" : "MM",
"leaf" : 'true',
"some_else": []
}]
}
]
}

The extJS tree I wish to get is:


Root
|--ED
|--ED2
|--MM

The model is just


Ext.define("User", {
extend: 'Ext.data.Model',
fields: [
'id', 'name'
],

hasMany: {model: 'Order', name: 'orders'},

proxy: {
type: 'ajax', //rest
url : 'my_file.json',
reader: {
type: 'json',
root: 'users'
}
}
});

Ext.define("Order", {
extend: 'Ext.data.Model',
fields: [
'id', 'name', 'info'
],
belongsTo: 'User'
});

The final output I get is just:


Root
|--ED
|--ED2

is it a mistake of mine, or a missing feature? Is there a way out without to change my json?

Thanks a lot
mario

tvanzoelen
4 Oct 2011, 11:10 PM
For I know now, it is a missing feature of the tree. Because of the restriction, nested data can only be put under the same root in JSON. Is a pitty, I haven't seen the solution yet.

I think you must be creative with some common fields for both user and orders. For example I use different icons on each nested level.

I see you have now the id field and the name field for both user and orders. Then the only thing to do is, rename the user and orders field in your JSON to 'children'. You can add an extra field type or icon for example to identify the node.

mario60
5 Oct 2011, 3:24 AM
Hello

thanks for the reply.
I see, if it is so, then it is a pity.

I get my json from another tool, which maps data from a sql DB. Clearly, i may rearrange things around, but it is not the way to go.

I do believe that there is a way out, it ought to be! extJS seems so powerful.

any advise?


cheers
mario

ps how do I print out the content of a store:
store.data.each .... ?