ExtJS: How to set defaults for Grid columns within initComponent?

╄→гoц情女王★ 提交于 2019-12-10 12:16:20

问题


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

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);
    },

and here is one of overrided functions

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

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


回答1:


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

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:

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
    }
}

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()
)


来源:https://stackoverflow.com/questions/50969190/extjs-how-to-set-defaults-for-grid-columns-within-initcomponent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!