Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [FIXED-547][3.1.1] ColumnModel#setConfig() -> this.config[i].destroy not a function

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    58

    Default [FIXED-547][3.1.1] ColumnModel#setConfig() -> this.config[i].destroy not a function

    I have a class that extends an existing grid, and adds an additional column to its existing columnmodel like this:

    PHP Code:
    var cm this.getColumnModel();
    var 
    config cm.config;
    config.push/* Description of extra column */ );
    cm.setConfig(config); 
    This used to work in 3.1.0, but breaks on 3.1.1 on calling cm.setConfig(config)

    Error: this.config[i].destroy is not a function
    Source File: http://[server]/ext/ext-all-debug.js
    Line: 1792

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661

    Default

    Can you post a working test case for this issue?

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Posts
    58

    Default

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css">
        <script type="text/javascript" src="../../adapter/ext/ext-base-debug.js"></script>
        <script type="text/javascript" src="../../ext-all-debug.js"></script>
        <script type="text/javascript">
    
            Ext.ns('Max');
            
            /**
             * Base grid with a number of columns
             */
            Max.BaseGrid = Ext.extend(Ext.grid.GridPanel, {
            
                initComponent: function()
                {
                    var cfg = {
                        viewConfig: {forceFit: true},
                        columns: [
                            {header: 'Column 1', dataIndex: 'a'},
                            {header: 'Column 2', dataIndex: 'b'}
                        ]
                    };
                    
                    Ext.apply(this, Ext.apply(this.initialConfig, cfg));
                    Max.BaseGrid.superclass.initComponent.apply(this, arguments);
                }
            });
            
            /**
             * Extended grid adds an additional column to BaseGrid
             */
            Max.ExtendedGrid = Ext.extend(Max.BaseGrid, {
            
                initComponent: function()
                {
                    Max.ExtendedGrid.superclass.initComponent.apply(this, arguments);
                    
                    var cm = this.getColumnModel();
                    var config = cm.config;
                    config.push({header: "Extra column", dataIndex: 'c'});
                    cm.setConfig(config);
                }
            });
            
            Ext.onReady(function() {
        
                var mystore = new Ext.data.ArrayStore({
                    fields: ['a','b','c']
                });
                
                var grid = new Max.ExtendedGrid({store: mystore});
                grid.render('mydiv');
            });
            
        </script>
    </head>
    
    <body>
        <div id="mydiv"></div>
    </body>
    </html>
    As a workaround I can remove the cm.setConfig() line, which does cause the third column to be displayed, but then columns are not sized correctly.

  4. #4
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661

  5. #5
    Sencha User mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,232

    Default

    i'm reposting the override i recommended in @saki's thread here:
    Quote Originally Posted by mystix View Post
    even better -- future-proof the ColumnModel's destroy() method by letting Ext.destroy() do all the work:
    Code:
    Ext.override(Ext.grid.ColumnModel, {
        destroy : function(){
            for(var i = 0, len = this.config.length; i < len; i++){
                Ext.destroy(this.config[i]);
            }
            this.purgeListeners();
        }
    });

  6. #6
    Sencha User
    Join Date
    Nov 2007
    Posts
    243

    Default

    Mystix, that override surely doesn't fix:

    PHP Code:
        setConfig : function(configinitial){
            var 
    iclen;
            if(!
    initial){ // cleanup
                
    delete this.totalWidth;
                for(
    0len this.config.lengthleni++){
                    
    this.config[i].destroy();
                }
            }
            ... 
    Think it's need in both places... or a new method destroyConfig to save the repeated code

  7. #7
    Sencha User mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,232

    Default

    righto -- my mistake, my bad.

    here's a full working override with your suggestion included:
    Code:
    Ext.override(Ext.grid.ColumnModel, {
        // private
        destroyConfig: function() {
            for (var i = 0, len = this.config.length; i < len; i++) {
                Ext.destroy(this.config[i]);
            }
        },
    
        destroy : function() {
            this.destroyConfig();
            this.purgeListeners();
        },
        
        setConfig: function(config, initial) {
            var i, c, len;
            if (!initial) { // cleanup
                delete this.totalWidth;
                this.destroyConfig();
            }
    
            // backward compatibility
            this.defaults = Ext.apply({
                width: this.defaultWidth,
                sortable: this.defaultSortable
            }, this.defaults);
    
            this.config = config;
            this.lookup = {};
    
            for (i = 0, len = config.length; i < len; i++) {
                c = Ext.applyIf(config[i], this.defaults);
                // if no id, create one using column's ordinal position
                if (Ext.isEmpty(c.id)) {
                    c.id = i;
                }
                if (!c.isColumn) {
                    var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
                    c = new Cls(c);
                    config[i] = c;
                }
                this.lookup[c.id] = c;
            }
            if (!initial) {
                this.fireEvent('configchange', this);
            }
        }
    });

  8. #8
    Sencha User
    Join Date
    Nov 2007
    Posts
    243

    Default

    Yep looks good to me mystic. Guess this is candidate for 3.1.2... And something adding to the known bugs list with 3.1.1 in the release notes might help people migrating?

  9. #9
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661

    Default

    Fixed in svn.

  10. #10
    Ext Premium Member
    Join Date
    May 2010
    Posts
    19

    Question Bug still there?

    Why do I get the error message mentioned here using ExtJS 3.3.1? The file .\src\widgets\grid\ColumnModel.js contains just the source lines which are supposed to have been fixed?! As soon as I include the override, everything works just fine. But shouldn't this be fixed in the framework?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •