0

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.

Nuri Engin
  • 813
  • 10
  • 38

1 Answers1

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()
)
scebotari66
  • 3,395
  • 2
  • 27
  • 34
  • Thanks for answer and this solution works perfectly but I just figure out that I need `flex` as default only for those columns which are rendering through `getListCols()` func. Is this possible to set defaults only for `getListCols`? – Nuri Engin Jun 27 '18 at 14:26
  • Worked perfectly! Thanks a lot @scebotari66 – Nuri Engin Jun 29 '18 at 12:15
  • I've with a new situation, could you give any idea about that? As you advice I've used `Ext.Array.map` and worked very well. The new situation is I need to set `flex` config as default but in nested array. Could you please check out my updated question for any advice. Thanks. – Nuri Engin Jul 04 '18 at 07:50
  • There are a couple of questions that arise for this particular situation, so I would suggest you to ask a new question in order to not pollute this one. – scebotari66 Jul 04 '18 at 09:30
  • thanks for opinion; moved to https://stackoverflow.com/questions/51171248/extjs-setting-defaults-to-panel-items-for-nested-objects – Nuri Engin Jul 04 '18 at 10:18