PDA

View Full Version : Add items to Panels



Killer_B
8 Nov 2010, 6:13 AM
Hello again! :)

I have a problem with adding new elements to a panel.

I have a panel with two items. The first item is another panel and the second item is a button. I managed to code so when I click on this button I add another panel at the end of these items. What I want is to somehow add this new panel before the button and behind the first panel. I used ADD function to append new panel but I can't control where to add it. The panel is automaticly placed at the end of the items.

Thanks for your help

Killer_B
8 Nov 2010, 6:26 AM
Well....I guess the solution could be to add another panel between the two elements and then just add new elements to that panel. That way all the new elements will stay between the first item and button. But that would be overnesting it. Is this the only option?

plalx
8 Nov 2010, 7:01 AM
Can't you put the button in the panel's footer instead, take a look at the buttons (http://dev.sencha.com/deploy/dev/docs/?class=Ext.Panel&member=buttons) panel config option?

You can also try to reorder the items.

E.g.


Ext.onReady(function() {
var p = new Ext.Panel({
renderTo: document.body,
height: 500,
width: 500,
items: [
{
title: 'P1'
},
{
xtype: 'button',
text: 'test',
handler: function() {
var ct = this.ownerCt;

ct.add({
xtype: 'panel',
title: 'P2'
});

ct.items.reorder({
'0' : 0,
'1': 2,
'2': 1
});

ct.doLayout();
}
}
]
});
});