extjs 布局在 vbox 内滚动

extjs layout scroll inside vbox

本文关键字:滚动 vbox 布局 extjs      更新时间:2023-09-26

我在向 vbox 容器内部的网格添加滚动条时遇到问题。我不能直接分配高度,因为我不知道。在该vbox容器中,还有未定义高度的"另一个内容",因此我既不能使用"高度",也不能使用"flex"。我需要让网格填充页面中的所有剩余空间,如果行数超过其容纳范围 - 我需要向该网格添加滚动条。这是代码中最重要的部分:

{
layout: {
    type: 'vbox',
    align: 'stretch'
}, 
items:[
    {
        title: 'center'
    },{
        html: 'another content'
    },{
        xtype: 'grid',
        autoScroll: true, // <-- this is not working
        columns: [
            { text: 'User', dataIndex: 'userId' }
        ],
        store: new Ext.data.Store({
            model: 'Ext.data.Record',
            fields: [
                { name: 'userId', type: 'string' }
            ],
            data: ( function(){
                var res = []
                for(var i=0; i<1000; i++){
                    res.push({ userId: 'User'+i});
                }
                return res;
            })()
        })
    }
]
}

我尝试了很多变体,但没有成功。我还为大多数逻辑解决方案准备了一些小提琴(但无论如何滚动在那里不起作用):

https://fiddle.sencha.com/#fiddle/fmohttps://fiddle.sencha.com/#fiddle/fmp

任何帮助都会很好。

只需删除autoScroll: true并将其替换为 flex: 1 即可。

https://fiddle.sencha.com/#fiddle/fms

Ext.application({
    name : 'Fiddle',
    launch : function() {
        Ext.create('Ext.container.Viewport', {          
            renderTo: Ext.getBody(),
            layout: {
                        type: 'border'
            },
            items: [
                {
                    width: '100%',
                    region: 'north',
                    items: [{
                        title: 'north'
                    },{
                        html: 'another content'
                    }]
                }, 
                {
                    region: 'center',
                    layout: 'fit',
                    items: [{
                        layout: {
                            type: 'vbox',
                            align: 'stretch'
                        }, 
                        items:[
                            {
                                title: 'center'
                            },{
                                html: 'another content'
                            },{
                                xtype: 'grid',
                                flex: 1,
                                columns: [
                                    { text: 'User', dataIndex: 'userId' }
                                ],
                                store: new Ext.data.Store({
                                    model: 'Ext.data.Record',
                                    fields: [
                                        { name: 'userId', type: 'string' }
                                    ],
                                    data: ( function(){
                                        var res = []
                                        for(var i=0; i<1000; i++){
                                            res.push({ userId: 'User'+i});
                                        }
                                        return res;
                                    })()
                                })
                            }
                        ]
                    }
                    ]
                }]
        });
    }
});