【发布时间】:2020-08-13 15:19:58
【问题描述】:
如何设置网格的高度以适应其内容?
在这里看到这个小提琴,第一个网格有一个height: 200,没关系。第二个没有高度,我想让高度适合网格内容。显示网格标题和列标题,但不显示网格行。
【问题讨论】:
标签: extjs
如何设置网格的高度以适应其内容?
在这里看到这个小提琴,第一个网格有一个height: 200,没关系。第二个没有高度,我想让高度适合网格内容。显示网格标题和列标题,但不显示网格行。
【问题讨论】:
标签: extjs
您可以在第二个网格中使用 layout: 'vbox' 和 flex: 1 。像这样的:
Ext.application({
name: 'Fiddle',
launch: function () {
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'email', 'phone'],
data: [{
'name': 'Lisa',
"email": "lisa@simpsons.com",
"phone": "555-111-1224"
}, {
'name': 'Bart',
"email": "bart@simpsons.com",
"phone": "555-222-1234"
}, {
'name': 'Homer',
"email": "home@simpsons.com",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "marge@simpsons.com",
"phone": "555-222-1254"
}]
});
Ext.create('Ext.Container', {
fullscreen: true,
layout: 'vbox',
defaults: {
style: 'border: 1px solid grey;' // To see the borders
},
items: [{
title: 'Simpsons - height: 200',
xtype: 'grid',
height: 200,
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
width: 200
}, {
text: 'Email',
dataIndex: 'email',
width: 250
}, {
text: 'Phone',
dataIndex: 'phone',
width: 120
}],
}, {
title: 'Simpsons - autofit?',
xtype: 'grid',
flex: 1,
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
width: 200
}, {
text: 'Email',
dataIndex: 'email',
width: 250
}, {
text: 'Phone',
dataIndex: 'phone',
width: 120
}],
}, {
xtype: 'container',
html: "Some other content"
}]
})
}
});
【讨论】:
解决方案是指定以下 2 个之一:
maxHeight 网格属性或
infinite 设置为false。 //maxHeight: 800,
infinite: false,
【讨论】: