Javascript 如何使 ExtJS 表格布局具有百分比而不是高度和宽度的绝对值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4968303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make an ExtJS table layout have percentage instead of absolute values for height and width?
提问by Edward Tanguay
Using Ext.Panel
and the table
layout, I was able to create a layout just the way I want. However, how do I change this code so that I can define the widths and heights proportionally?
使用Ext.Panel
和table
布局,我能够按照我想要的方式创建布局。但是,如何更改此代码以便可以按比例定义宽度和高度?
e.g. the table should not be 800 pixels but 100% of the screen width, and each box not 200 pixels but 25%.
例如,表格不应该是 800 像素,而是屏幕宽度的 100%,每个框不应该是 200 像素,而是 25%。
here is the code:
这是代码:
<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>
回答by George Vourdanos
Instead of :
代替 :
layout:'table',
layoutConfig: {columns:2},
try this :
尝试这个 :
layout: {
type: 'table',
columns: 3,
tableAttrs: {
style: {
width: '100%',
height: '100%'
}
}
},
回答by Dharmesh Hadiyal
try this one fiddle example : https://fiddle.sencha.com/#fiddle/2dm
试试这个小提琴示例:https: //fiddle.sencha.com/#fiddle/2dm
Ext.create('Ext.panel.Panel', {
title: 'Car Simple Tree',
height: 200, //Fixed height for this panel
renderTo: Ext.getBody(),
layout: {
type: 'table',
columns: 2,
tableAttrs: {
style: {
width: '100%' // To make the cell width 100%
}
}
},
items: [{
xtype: 'panel',
title: 'panel title',
collapsible: true,
titleCollapse: true,
bodyStyle: {
background: '#D9E5F3',
borderColor: '#99BCE8',
borderWidth: '1px'
},
//scrollable: true,
//autoScroll: true,
layout: {
pack: 'center',
type: 'hbox'
},
rowspan: 1,
colspan: 2,
width: '100%',
items: [{
text: 'Save',
xtype: 'button',
padding: 5
}]
}, {
html: 'Cell C content',
cellCls: 'highlight'
}, {
html: 'Cell D content'
}]
});
回答by Rob Boerman
Like I said in the reply to your other thread using vbox and hbox layouts might be a little easier for you if you want to do relative positioning. Also, if you want to stretch things to your window, put it in a Viewport, that automatically uses you entire window.
就像我在回复您的其他线程中所说的那样,如果您想进行相对定位,使用 vbox 和 hbox 布局对您来说可能会更容易一些。另外,如果你想把东西拉伸到你的窗口,把它放在一个视口中,它会自动使用你的整个窗口。
You might want to change the layout a bit (borders, frames), but with vbox and hbox layouts it would be something like this:
您可能想要稍微更改布局(边框、框架),但是对于 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
}]
}]
}]
}
]
});
回答by Matthew Strawbridge
Consider using ColumnLayout
instead. This gives you a choice between pixels and percentages for widths.
考虑ColumnLayout
改用。这使您可以在像素和宽度百分比之间进行选择。