【问题标题】:ExtJS - autoScroll doesn't show in nested gridExtJS - autoScroll 不显示在嵌套网格中
【发布时间】:2014-07-26 21:21:33
【问题描述】:

在过去的 24 小时内,我一直在努力寻找此问题的答案,但找不到解决此问题的方法。这里是:

我正在使用带有 ExtJS 4 的 MVC 架构。我有一个选项卡面板,其中包含一些网格作为项目。当这些网格加载时,它们没有垂直滚动条,即使我将 autoScroll 设置为“true”并且它们的内容大于屏幕可以显示的内容。我读到的关于这个问题的每一篇文章都已解决,将网格的父布局设置为“适合”,但是,如下所示,我已经完成了,但仍然没有滚动条......如果我为网格定义了一个高度,则滚动条完美地工作,但我需要它以不同的高度工作...... 我相信我可能有一个过度嵌套的问题,但我几天前才开始使用 ExtJS 进行开发,它仍然让我有点困惑......

问题是:如何使这个结构与 autoScroll 一起工作?

因为我的声誉低于 10,所以不允许我在这里发布图片,so you can find my app's structure here

请注意,我在图片中写了“layout: 'fix'”,但我的意思是“layout: 'fit'”:)

这是我的主视图,有 2 个面板。 “中心”是我加载具有网格的标签面板的地方。

Ext.define('MyApp.view.Main', {
extend: 'Ext.container.Container',

requires:[
    // 'Ext.tab.Panel',
    // 'Ext.layout.container.Border',
    'MyApp.view.Menus'
],

xtype: 'app-main',

layout: {
    type: 'border'
},

items: [
    {
        region: 'north',
        xtype: 'panel',
        padding: '5 5 0 5',
        title: 'MyApp',
        items: {
            xtype: 'menus'
        }
    }, 
    {
        region: 'center',
        itemId: 'centerPanel',
        xtype: 'panel',
        padding: 5,
        layout: 'fit'
    }
]
});

这是将字段集和选项卡面板作为项目的视图:

Ext.define('MyApp.view.licencas.List', {
extend: 'Ext.form.Panel',
xtype: 'licencaslist',
title: 'Licenças de software',
border: false,
items: [
    {
        xtype: 'fieldset',
        title: 'Dados do Veículo',
        margin: 5,
        items: [
            {
                xtype: 'combobox',
                anchor: '100%',
                valueField: 'id',
                displayField: 'descricao',
                store: 'ComboEmpresas',
                typeAhead: true,
                queryMode: 'local',
                name: 'empresa',
                fieldLabel: 'Empresa'
            },
            {
                xtype: 'combobox',
                editable: false,
                valueField: 'id',
                displayField: 'descricao',
                store: 'ComboSoftwares',
                queryMode: 'local',
                name: 'software',
                fieldLabel: 'Software'
            },
            {
                name: 'valor',
                fieldLabel: 'Valor empresa:',
                xtype: 'numberfield',
                minValue: 0,
                maxValue: 100000,
                allowDecimals: true,
                disabled: true,
            },
            {
                name: 'contrato',
                fieldLabel: 'Contrato:',
                xtype: 'textfield',
                disabled: true,
            },
            {
                name: 'demonstracao',
                xtype: 'checkbox',
                fieldLabel: 'Demonstração',
                disabled: true,
            }
        ]
    },
    {
        xtype: 'licencastabpanel',
        border: false,
        margin: 5
    }
],

initComponent: function() {
    this.callParent(arguments)
}
});

最后,这是我需要 autoScroll 属性的网格...

Ext.define('MyApp.view.licencas.placas.List', {
extend: 'Ext.grid.Panel',
xtype: 'licencasplacaslist',
store: 'EmpresaVeiculos',
border: false,
forceFit: true,
autoScroll: true,
plugins: [new Ext.grid.plugin.CellEditing({
    clicksToEdit: 1,
})],
dockedItems: [
    {
        dock: 'top',
        xtype: 'toolbar',
        items: [
            {
                text: 'Alterar todos',
                iconCls: 'money-16',
                action: 'alterartodos',
                xtype: 'button'
            },
            '->',
            {
                xtype: 'trigger',            
                name: 'searchfieldLicencasPlacas',
                itemId: 'searchfieldLicencasPlacas',
                emptyText: 'Filtrar por placa...',
                width: '500px',
                hideLabel: true,
                selectOnFocus: true,
                triggerCls: 'x-form-search-trigger'
            }                     
        ]
    }
],
columns: [
    Ext.create('Ext.grid.RowNumberer'),
    {       
        text: "Placa",
        dataIndex: 'placa',
        width: 70
    },
    {       
        text: "Serial",
        dataIndex: 'serial',
        width: 70
    },
    {
        text: "Condutor",
        dataIndex: 'condutor'
    },
    {
        text: "Ativo",
        dataIndex: 'ativo',
        width: 50
    },
    {
        text: "Data Início",
        dataIndex: 'data_inicio',
        format: 'd.m.Y',
        width: 60
    },
    {
        text: "Data Fim",
        dataIndex: 'dt_fim',
        format: 'd.m.Y',
        width: 60,
        editor: {
            xtype: 'datefield',
            format: 'd.m.Y'
        }
    },
    {
        text: "Contrato",
        dataIndex: 'contrato',
        width: 70,
        editor: {
            xtype: 'textfield'
        }
    },
    {
        text: "Software",
        dataIndex: 'valor_software',
        renderer: 'usMoney',
        width: 70,
        editor: {
            xtype: 'numberfield',
            minValue: 0,
            maxValue: 1000,
            allowDecimals : true
        }
    },
    {
        text: "Comunicação",
        dataIndex: 'valor_comunicacao',
        renderer: 'usMoney',
        width: 70,
        editor: {
            xtype: 'numberfield',
            minValue: 0,
            maxValue: 1000,
            allowDecimals : true
        }
    },
    {
        text: "Comodato",
        dataIndex: 'valor_comodato',
        renderer: 'usMoney',
        width: 70,
        editor: {
            xtype: 'numberfield',
            minValue: 0,
            maxValue: 1000,
            allowDecimals : true
        }
    },
    {
        text: 'Empresa para faturar',
        dataIndex: 'fatura',
        width: 200,
        editor:
            {
                xtype: 'combobox',
                displayField: 'descricao',
                valueField: 'descricao',
                store: 'ComboFaturas',
                name: 'software',
                queryMode: 'local'
            }

    }
],

initComponent: function() {
    this.callParent(arguments)
}
});

请注意,我从代码中删除了所有“布局:'fit'”(除了主视图,它对其他视图有影响),因为它无论如何都不起作用......:)

如果我需要为您提供任何额外信息,请告诉我。我试图通过下图使其更容易理解。

谢谢你们!

【问题讨论】:

  • 请贴出您的代码,并指定您使用的ExtJs版本,这样会更容易帮助您
  • 你说得对,我之前没有发布代码,因为我认为它会太多......我用代码编辑了帖子......而且我正在使用 ExtJS 4。谢谢! :)

标签: extjs autoscroll


【解决方案1】:

它的工作原理如下:

  1. grid 忽略 autoScroll 配置选项
  2. 网格需要一个高度,可以是显式的,也可以由其父容器的布局控制
  3. 如果网格没有高度,它会根据存储中加载的记录数尝试垂直扩展,这样它就不会显示滚动条
  4. fit 布局只能有一项 - 如果是网格,则其高度(和宽度)由父容器的大小控制

总结一下:如果你想让一个网格滚动,它必须有一个高度。

【讨论】:

  • 嗨咲!感谢您的回复...我想根据它的父容器来控制我的网格的大小,所以我需要将它的父容器布局定义为“适合”,对吗?但是,如果这个父容器已经有一个具有“适合”布局的“父容器”,它会起作用吗?
  • 是的,您可以在容器中嵌套容器,但不要不必要地这样做。另外,请注意每个嵌套级别都配置了一些layout
猜你喜欢
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-26
相关资源
最近更新 更多