ExtJS:如何在 initComponent 中为 Grid 列设置默认值? [英] ExtJS: How to set defaults for Grid columns within initComponent?

查看:69
本文介绍了ExtJS:如何在 initComponent 中为 Grid 列设置默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您在下面注意到的,我正在使用 Ext.Array.mergeinitComponent 中呈现 columns.

as you notice below, I'm using Ext.Array.merge to render columns within initComponent.

我正在尝试在 initComponent 中将 columnsflex 属性设置为默认值.我怎样才能实现这种安排?

I'm try to set columns' flex property as default in initComponent. How can I achieve to this arrangement?

initComponent: function () {
        var me = this;
        Ext.on('resize', function () { me.height = window.innerHeight - App.MAIN_FOOTER_HEIGHT - App.MAIN_HEADER_HEIGHT - 100 });

        me.createGridMenu();

        me.columns = Ext.Array.merge(me.getListColsStart(), me.getListCols(), me.getListColsEnd());

        //I need to set through here. Any solution such as setDefaults or dot notation to fetch defaults of columns?

        me.callParent(arguments);
    },

这是一个被覆盖的函数

getListCols: function () {
        return [];
    },

更新:相关的第二个问题移至 设置嵌套对象的面板项的默认值 发布.仅供参考.

UPDATE: Related second question moved to Setting defaults to panel items for nested objects post. FYI.

推荐答案

这里是 API Docs 的摘录,来自 columns 文档(它还包含与您的问题相关的示例):

Here is an excerpt from the API Docs, from the columns documentation (it also contains an example related to your question):

这也可以是一个配置对象Ext.grid.header.Container 可能会覆盖某些默认值必要时进行配置.例如,特殊布局可能是重写以使用更简单的布局,或者可以设置默认值由所有列共享:

This can also be a configuration object for a Ext.grid.header.Container which may override certain default configurations if necessary. For example, the special layout may be overridden to use a simpler layout, or one can set default values shared by all columns:

因此,在您的情况下,您可以将 flex 设置为所有列的默认配置:

So, in your case, here is how you can setup flex as a default config for all columns:

me.columns = {
    items: Ext.Array.merge(
        me.getListColsStart(),
        me.getListCols(),
        me.getListColsEnd()
    ),
    defaults: {
        flex: 1
    }
}

编辑如果 flex 属性必须仅应用于列的子集,实现此目的的一种方法是应用数组 map 函数在所需子集上:

EDIT If the flex property must be applied only to a subset of columns, one way to achieve this is by applying the array map function on the needed subset:

me.columns = Ext.Array.merge(
    me.getListColsStart(),
    Ext.Array.map(me.getListCols(), function(listColConfig) {
        listColConfig.flex = 1;
        return listColConfig;
    }),
    me.getListColsEnd()
)

这篇关于ExtJS:如何在 initComponent 中为 Grid 列设置默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆