PDA

View Full Version : Extjs 4.2.1 tree-grid and metadata



shkiper
26 Feb 2014, 10:48 PM
I want to use an extjs 4 tree panel as a grid. The problem is I don't know how many columns it'll be have as well as fields. So I'm trying to get luck with metaData of a tree store. I don't know what I'm doing wrong but it renders a checkbox instead of just a tree node.
http://i.stack.imgur.com/kAcJ2.png

I've already asked it in stackoveflow but no one helped me so far. http://stackoverflow.com/questions/21648430/extjs-4-2-treegrid-and-metadata

scottmartin
27 Feb 2014, 5:59 PM
Are you wanting to setup something like the treegrid?
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/build/KitchenSink/ext-theme-neptune/#tree-grid

Here is a post on setting up with metadata:
http://www.sencha.com/forum/showthread.php?254168

shkiper
28 Feb 2014, 2:42 AM
Are you wanting to setup something like the treegrid?
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/build/KitchenSink/ext-theme-neptune/#tree-grid

Here is a post on setting up with metadata:
http://www.sencha.com/forum/showthread.php?254168

Yes, I want a tree with a grid. I used it with static model very well, but when I faced with the task that suppose to use dynamic fields it doesn't work.

I don't really undestand what's wrong with this simple code. I don't know why I see a checkbox opposite the node and tree couldn't show nested nodes (below the node with the checkbox). I spent a lot of time, but nothing helped me.

shkiper
6 Mar 2014, 10:25 AM
I solved my problem. I really think it was a bug.

listeners: {
metachange: function (store, meta) {
tree = Ext.ComponentQuery.query('#myTree')[0];
Ext.each(meta.treeFields, function (treeField) { //not meta.fields, it must be a different (http://www.lingvo-online.ru/ru/Search/Translate/GlossaryItemExtraInfo?text=%d0%be%d1%82%d0%bb%d0%b8%d1%87%d0%bd%d1%8b%d0%b9&translation=different&srcLang=ru&destLang=en) name
store.model.fields.add(new Ext.data.Field(treeField));
})
tree.reconfigure(store, meta.columns);
}
} //works fine

But when I'm hoping to magic fields binding it doesn't work.

listeners: {
metachange: function (store, meta) {
tree = Ext.ComponentQuery.query('#myTree')[0];
tree.reconfigure(store, meta.columns);
}
} //don't work properly

Interesting enough that if I am naming array of fields like 'fields' in the first variant it doesn't work either.

yclick
1 Apr 2015, 2:51 AM
...if someone else need the answer :

When a treestore load a json recordset, if the server provides metaData, the proxy.reader reset the fields of the model. That's normal but the TreeStore needs extra fields and they are erased because of this operation.

A workaround would be to redecorate the model after a "MetaChange" occurs.

The following lines are intended to be used in an override from Ext.data.TreeStore.



onMetaChange:function()
{
this.model.prototype.isNode = false; // without that, the nodeinterface think that the model is already decorated.
Ext.data.NodeInterface.decorate(this.model); // redecorate the model
this.callParent(arguments); // let the event go further
}