在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文档:

GridPanel

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').

如果未指定,默认情况下,网格的宽度当然会采用容器的宽度。
Ext.grid.GridPanel#autoExpandColumn将帮助扩展网格中占据静止水平空间的一列。还将有助于查看Ext.grid.GridView的forceFit和autoFill调整列的宽度。

关于extjs - ExtJS 3网格自动宽度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11369309/

10-13 03:16