PDA

View Full Version : Tree Panel ignores root when store is a string



alamottemitchell
16 Aug 2012, 3:03 PM
I have an Ext.tree.Panel, which I want to configure like so:


Ext.define('myTest.CoolTree', {
extend:'Ext.tree.Panel',
alias:'widget.coolTree',
store:'coolTreeStore',
rootVisible:true,
root: {
text: 'All',
expanded: true
}
});


If I do this, it completely ignores my root config, and uses the default (text=Root, expanded=false). It appears this is because the initComponent function for Ext.tree.Panel has a 3-part conditional whose first if is overly broad:



Ext.define('Ext.tree.Panel', {
...
initComponent: function() {
...
if (Ext.isString(me.store)) {
me.store = Ext.StoreMgr.lookup(me.store);
} else if (!me.store || Ext.isObject(me.store) && !me.store.isStore) {
me.store = new Ext.data.TreeStore(Ext.apply({}, me.store || {}, {
root: me.root,
fields: me.fields,
model: me.model,
folderSort: me.folderSort
}));
} else if (me.root) {
me.store = Ext.data.StoreManager.lookup(me.store);
me.store.setRootNode(me.root);
if (me.folderSort !== undefined) {
me.store.folderSort = me.folderSort;
me.store.sort();
}
}
...


My string is a store, so the first case hits, and that case ignores root. Is that intentional? For my use, I want to hit the last else-if, where it treats my store as a string (it is) and respects my root config.

My workaround is to override initcomponent, call parent, and then:



me.setRootNode({text:'All', expanded:true});


I'd definitely prefer to not do that. Thoughts?

redraid
17 Aug 2012, 4:14 AM
Move

root: {
text: 'All',
expanded: true
}
from tree to TreeStore