Nuri Engin
Nuri Engin

Reputation: 823

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

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.

Upvotes: 0

Views: 1121

Answers (1)

scebotari66
scebotari66

Reputation: 3480

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

Upvotes: 1

Related Questions