使用Ext.Panel
和table
布局,我能够按照我想要的方式创建布局.但是,如何更改此代码以便我可以按比例定义宽度和高度?
例如,表格不应该是800像素而是100%的屏幕宽度,每个框不是200像素而是25%.
这是代码:
<script type="text/javascript">
clearExtjsComponent(targetRegion);
var table_wrapper2 = new Ext.Panel({
id: 'table_wrapper2',
baseCls: 'x-plain',
renderTo: Ext.getBody(),
layout:'table',
layoutConfig: {columns:2},
defaults: {
frame:true,
width:200,
height: 200,
style: 'margin: 0 10px 10px 0'
},
items:[{
title:'Shopping Cart',
width: 400,
height: 290,
colspan: 2
},{
title:'Invoice Address',
width: 190,
height: 100
},{
title:'Delivery Address',
width: 200,
height: 100
}
]
})
var table_wrapper = new Ext.Panel({
id:'table_wrapper',
baseCls:'x-plain',
renderTo: Ext.getBody(),
layout:'table',
layoutConfig: {columns:4},
defaults: {
frame:true,
width:200,
height: 200,
style: 'margin: 10px 0 0 10px'
},
items:[{
title:'Orders',
width: 810,
colspan: 4
},{
title:'Customer Information',
width: 400,
height: 400,
colspan: 2
},{
//title:'Shopping Cart',
frame: false,
border: false,
width: 400,
height: 400,
colspan: 2,
items: [ table_wrapper2 ]
}
]
});
replaceComponentContent(targetRegion, table_wrapper);
hideComponent(regionHelp);
</script>
Run Code Online (Sandbox Code Playgroud)
小智 5
代替 :
layout:'table',
layoutConfig: {columns:2},
Run Code Online (Sandbox Code Playgroud)
尝试这个 :
layout: {
type: 'table',
columns: 3,
tableAttrs: {
style: {
width: '100%',
height: '100%'
}
}
},
Run Code Online (Sandbox Code Playgroud)
就像我在回复您的其他线程时所说,如果您想进行相对定位,那么使用 vbox 和 hbox 布局可能会更容易一些。另外,如果您想将内容拉伸到窗口,请将其放入视口中,它会自动使用整个窗口。
您可能想稍微更改一下布局(边框、框架),但是对于 vbox 和 hbox 布局,它会是这样的:
new Ext.Viewport({
layout: 'vbox',
layoutConfig: {
align : 'stretch',
pack : 'start'
},
defaults: {
style: 'margin: 10px 0 0 10px'
},
items:[{
title:'Orders',
height: 200
},{
layout: 'hbox',
flex: 1,
layoutConfig: {
align : 'stretch',
pack : 'start'
},
items: [{
title:'Customer Information',
flex: 1
},{
layout: 'vbox',
flex: 1,
layoutConfig: {
align : 'stretch',
pack : 'start'
},
items: [{
title: 'Shopping cart',
height: 200
},{
layout: 'hbox',
flex: 1,
layoutConfig: {
align : 'stretch',
pack : 'start'
},
items: [{
title: 'Invoice address',
flex: 1
},{
title: 'Delivery address',
flex: 1
}]
}]
}]
}
]
});
Run Code Online (Sandbox Code Playgroud)