PDA

View Full Version : [SOLVED] TreePanel as xtype in ViewPort



ittayd
4 Aug 2009, 12:53 PM
[see the solution post below]

Hi,

I'm a newbie trying to get a tree to work from static data:
Dashboard.LibraryPanel = Ext.extend(Ext.tree.TreePanel, {
border:false,
initComponent: function() {
Ext.apply(this, {
dataUrl: 'get-nodes.php',

root: {
nodeType: 'async',
text: 'Ext JS',
draggable: false,
id: 'source'
}

});

Dashboard.LibraryPanel.superclass.initComponent.apply(this, arguments);
},

onRender: function() {
// this.store.load();

Dashboard.LibraryPanel.superclass.onRender.apply(this, arguments);
}

});

Ext.reg('dashboard_librarypanel', Dashboard.LibraryPanel);

Ext.onReady(function() {

Ext.QuickTips.init();
var viewport = new Ext.Viewport({
id:'dashboard',
layout:'border',
border:false,
items:[{
region: 'west',
id: 'dashboard_library',
title: 'Library',
xtype: 'dashboard_librarypanel',
split: true,
width: 212,
maxsize: 400,
collapsible: true,
},{
region: 'center',
id: 'dashboard_main',
title: 'Main',
xtype: 'dashboard_mainpanel',
split: true,
enableTabScroll: true,
}]
});
});

the root of the tree is rendered, but not the rest. i searched for examples, but they all use an instance of a tree rather than xtype (then things like tree.render(); root.expand(); are probably what makes it work)

Thanks,
Ittay

Animal
4 Aug 2009, 1:01 PM
"not the rest"?

You haven't expanded the root, so it will show no child nodes until you do.

At that point, it will make a request to "get-nodes.php?node=source" which must return an Array of child node configs.

ittayd
4 Aug 2009, 7:47 PM
In initComponent, if I try to write root.expand() I get an error that root is not defined. Same if I put it in onRender.

ittayd
4 Aug 2009, 8:01 PM
the tree renders with one node, the root. when i click on it, it has no children

Animal
4 Aug 2009, 9:03 PM
OK, you have a bug.

Is the request being sent?

What's returning from the server?

ittayd
4 Aug 2009, 9:23 PM
i added the code below to the TreePanel extension, but the function in the listener data is undefined when the code runs. since 'this' is the window (and window doesn't have onLoadException). how can I set the function correctly (assuming i don't want to inline it)
onLoadException: function(treePanel, node, response) {
Ext.MessageBox.alert(
document.title,
Data.Strings.ErrorLoaderException);
},

listeners: {
loadexception: {fn: this.onLoadException, scope: this}
}

Animal
4 Aug 2009, 9:27 PM
If you are not using Firebug, then I'm checking out.

ittayd
4 Aug 2009, 9:49 PM
that is how i saw i have a loadexception and wanted to add the listener.

i'm getting a "communication failure"

I should mention that i'm trying to run the code locally (file://..../index.html)

ittayd
4 Aug 2009, 10:22 PM
so the reason is that extjs' ajax doesn't support local file read. fortunately, a project named ext-basex adds this support. just stick the ext-basex.js after ext-all.js and all is well....