I am a beginner of extjs.
I want to arrange some TextFields as below:
a:______ b:______ c:______
d:______ e:______ f:______
here are my test codes below:
Ext.onReady(function()
{
new Ext.panel.Panel(
{
renderTo: Ext.getBody(),
layout:'vbox',
width: 670,
tbar: [{text:"Add"}],
defaults:
{
layout:"column",
height:50
},
items:
[
{
defaults:
{
labelAlign:"right",
labelWidth:50
},
items:
[
{
xtype: 'textfield',
fieldLabel: 'a'
},
{
xtype: 'textfield',
fieldLabel: 'b'
},
{
xtype: 'textfield',
fieldLabel: 'c'
}
]
},
{
defaults:
{
labelAlign:"right",
labelWidth:50
},
items:
[
{
xtype: 'textfield',
fieldLabel: 'd'
},
{
xtype: 'textfield',
fieldLabel: 'e'
},
{
xtype: 'textfield',
fieldLabel: 'f'
}
]
}
]
});
});
as a result, the page can't display any TextFields.
Thank you for any help in advance!
You can do something like :
new Ext.panel.Panel({
renderTo: Ext.getBody(),
width: 670,
tbar: [{
text: "Add"
}],
defaults: {
layout: ,
height: 50
},
items: [{
defaults: {
labelAlign: "right",
labelWidth: 50
},
items: [{
xtype: 'textfield',
fieldLabel: 'a'
}, {
xtype: 'textfield',
fieldLabel: 'b'
}, {
xtype: 'textfield',
fieldLabel: 'c'
}]
}, {
defaults: {
labelAlign: "right",
labelWidth: 50
},
items: [{
xtype: 'textfield',
fieldLabel: 'd'
}, {
xtype: 'textfield',
fieldLabel: 'e'
}, {
xtype: 'textfield',
fieldLabel: 'f'
}]
}]
});
It is essentially your same example except replacing the vbox
layout with the default auto
layout. The reason why you example didn't work is that vbox
layouts need a height and width set on it somehow.
You could also do something like :
new Ext.panel.Panel({
renderTo: Ext.getBody(),
layout: 'column',
width: 670,
tbar: [{
text: "Add"
}],
defaults: {
labelAlign: "right",
labelWidth: 50
},
items: [{
xtype: 'textfield',
fieldLabel: 'a'
}, {
xtype: 'textfield',
fieldLabel: 'b'
}, {
xtype: 'textfield',
fieldLabel: 'c'
}, {
xtype: 'textfield',
fieldLabel: 'd'
}, {
xtype: 'textfield',
fieldLabel: 'e'
}, {
xtype: 'textfield',
fieldLabel: 'f'
}]
});
It is a column
layout without the nested items as the one before. One nice thing about a column
layout is that it will shift as many items as it can to the left and if an item can't fit it will go in the next row.
Since the width is a static 670 it can only fit 3 text fields per row. Column layouts do not need a height set.