Threaded View

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    174
    Vote Rating
    1
    Answers
    10
    netemp is on a distinguished road

      0  

    Default Answered: Extending Grid giving error with initConfig()

    Answered: Extending Grid giving error with initConfig()


    We need to extend the grid component and add new properties to it.

    Below is simplified version of the code we are using for it:

    Code:
    Ext.define('Ext.pnc.Grid',{
        extend: 'Ext.grid.Panel',
        alias: 'widget.pncgrid',
        config:{
            showCountColumn:true//a new property added
        },
        constructor:function(config){
            this.initConfig(config);//This line is throwing error -> me.additionalCls is undefined on ext-all-debug.js (line 17129)
            this.callParent(arguments);
        }
    });

    Here line this.initConfig(config); is producing the error - me.additionalCls is undefined ext-all-debug.js (line 17129).

    We have extended other components too, like window, textfield etc.. and used the same approach but have never faced this error.

    The error goes off as soon as the line this.initConfig(config) is commented. But if we comment this line then how will the new properties defined in config be initialized?

    Could someone guide at this?

    Thanks in advance.

  2. All the config object does is create the get and set methods so you don't have to use it.

    Code:
    Ext.define('Ext.pnc.Grid', {
        extend: 'Ext.grid.Panel',
        alias: 'widget.pncgrid',
    
        showCountColumn: true, //a new property added
    
        getShowCountColumn : function() {
            return this.showCountColumn;
        },
    
        setShowCountColumn : function(value) {
            var me = this,
                oldValue = me.getShowCountColumn();
    
            if (me.applyShowCountColumn) {
                value = me.applyShowCountColumn(value, oldValue);
            }
    
            if (!Ext.isDefined(value)) {
                return;
            }
    
            this.showCountColumn = value;
    
            if (me.updateShowCountColumn) {
                this.updateShowCountColumn(value, oldValue);
            }
        }
    });
    That would do the same thing just without calling initConfig and you get the get and set and the set method takes advantage of the apply and update methods just like initConfig does.

Thread Participants: 1

Tags for this Thread