在 ExtJS 3 中,如何将网格设置为自动宽度?我已经尝试了下面的代码,它不起作用。
谢谢
var exceptionGrid = new Ext.grid.GridPanel({
store: exceptionStore,
loadMask: true,
frame: true,
// defaultWidth: 450,
//height: 560,
autoHeight: true,
autoWidth: true,
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [{
header: 'COL1',
dataIndex: 'COL1'
}, {
header: 'COL2',
dataIndex: 'COL2'
}, {
header: 'COL3',
dataIndex: 'COL3'
}, .....]
}),
viewConfig: {
forceFit: false
}
});
最佳答案
来自 extjs 3 文档:
Notes:
- Although this class inherits many configuration options from base
classes, some of them (such as autoScroll, autoWidth, layout, items,
etc) are not used by this class, and will have no effect.
- A grid requires a width in which to scroll its columns, and a height
in which to scroll its rows. These dimensions can either be set
explicitly through the height and width configuration options or
implicitly set by using the grid as a child item of a Container which
will have a layout manager provide the sizing of its child items (for
example the Container of the Grid may specify layout:'fit').
如果未指定,Grid 的宽度默认采用容器宽度。 Ext.grid.GridPanel#autoExpandColumn 将有助于扩展网格中的一列,占用剩余的水平空间。查看 Ext.grid.GridView 的 forceFit 和 autoFill 调整列宽也很有帮助。
关于ExtJS 3 网格自动宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11369309/