Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ext JS GridPanel基于行数的动态高度_Javascript_Extjs - Fatal编程技术网

Javascript Ext JS GridPanel基于行数的动态高度

Javascript Ext JS GridPanel基于行数的动态高度,javascript,extjs,Javascript,Extjs,使用ExtJSGridPanel时,我面临着一个两难境地:用于加载其存储的数据是动态的,因此我事先不知道网格上需要显示多少行 因此,我在网格的高度方面遇到了困难:我尝试将autoHeight设置为true,但网格将只显示第一行,而隐藏其余的行;当我显式设置其高度时,如果行数没有填充高度指定的空间,则网格上会出现空白 理想情况下,栅格应垂直展开/收缩以显示其所有行。 有没有办法根据网格包含的行数使网格的高度动态化 我可以等待网格渲染,获得行数,然后根据这些行数重新计算网格的高度,但它看起来很粗糙,

使用ExtJSGridPanel时,我面临着一个两难境地:用于加载其存储的数据是动态的,因此我事先不知道网格上需要显示多少行

因此,我在网格的高度方面遇到了困难:我尝试将autoHeight设置为true,但网格将只显示第一行,而隐藏其余的行;当我显式设置其高度时,如果行数没有填充高度指定的空间,则网格上会出现空白

理想情况下,栅格应垂直展开/收缩以显示其所有行。 有没有办法根据网格包含的行数使网格的高度动态化

我可以等待网格渲染,获得行数,然后根据这些行数重新计算网格的高度,但它看起来很粗糙,我正在寻找更干净的东西

这是我的代码供参考:

var store = new Ext.data.ArrayStore({fields:[{name: 'sign_up_date'}, {name: 'business_name'}, {name: 'owner_name'}, {name: 'status'}]});
// buildResultsArray is a method that returns arrays of varying lengths based on some business logic. The arrays can contain no elements or up to 15
store.loadData(buildResultsArray()); 
var resultsGrid = new Ext.grid.GridPanel({
    store: store,
    columns: [
        {id: "sign_up_date", header: "Sign Up Date", dataIndex: "sign_up_date", width: 70}, 
        {id: "business_name", header: "Business Name", dataIndex: "business_name", width: 100}, 
        {id: "owner_name",header: "Owner Name", dataIndex: "owner_name", width: 100},
        {id: "status", header: "Sign Up Status", dataIndex: "status", width: 70}
    ],
    stripeRows: true,
    columnLines: true,
    enableColumnHide: false,
    enableColumnMove: false,
    enableHdMenu: false,
    id: "results_grid",
    renderTo: "results_grid_div", 
    //height: 300,
    autoHeight: true, 
    selModel: new Ext.grid.RowSelectionModel({singleSelect: false})
});

感谢您的帮助。

在ExtJS 3中,它不是开箱即用的,但通过扩展GridView,它很容易实现:

AutoGridView = Ext.extend(
    Ext.grid.GridView,
    {
        fixOverflow: function() {
            if (this.grid.autoHeight === true || this.autoHeight === true){
                Ext.get(this.innerHd).setStyle("float", "none");
                this.scroller.setStyle("overflow-x", this.scroller.getWidth() < this.mainBody.getWidth() ? "scroll" : "auto");
            }
        },
        layout: function () {
            AutoGridView.superclass.layout.call(this);
            this.fixOverflow();
        },
        render: function(){
            AutoGridView.superclass.render.apply(this, arguments);

            this.scroller.on('resize', this.fixOverflow, this);

            if (this.grid.autoHeight === true || this.autoHeight === true){
                this.grid.getStore().on('datachanged', function(){
                    if (this.ownerCt) { this.ownerCt.doLayout(); }
                }, this.grid, { delay: 10 });
            }
        }
    }
);

应该有
autoglidview
而不是
sm.GridView
。我已经更正了我的代码。
new Ext.grid.GridPanel({
    autoHeight: true,
    view: new AutoGridView()
});