PDA

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



Max_nl
9 Feb 2010, 11:40 AM
I have a class that extends an existing grid, and adds an additional column to its existing columnmodel like this:


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

Jamie Avins
9 Feb 2010, 12:15 PM
Can you post a working test case for this issue?

Max_nl
9 Feb 2010, 1:36 PM
<!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.

Jamie Avins
9 Feb 2010, 1:56 PM
Thank you, also ref: http://www.extjs.com/forum/showthread.php?t=91635

mystix
9 Feb 2010, 7:05 PM
i'm reposting the override i recommended in @saki's thread here:

even better -- future-proof the ColumnModel's destroy() method by letting Ext.destroy() do all the work:


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

JamesC
10 Feb 2010, 5:11 AM
Mystix, that override surely doesn't fix:



setConfig : function(config, initial){
var i, c, len;
if(!initial){ // cleanup
delete this.totalWidth;
for(i = 0, len = this.config.length; i < len; i++){
this.config[i].destroy();
}
}
...


Think it's need in both places... or a new method destroyConfig to save the repeated code

mystix
10 Feb 2010, 8:42 AM
righto -- my mistake, my bad.

here's a full working override with your suggestion included:


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

JamesC
10 Feb 2010, 10:38 AM
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?

Jamie Avins
10 Feb 2010, 11:21 AM
Fixed in svn.

MarkusL
22 Dec 2010, 2:56 AM
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?

meroy
29 Dec 2010, 11:43 AM
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?

Can you submit a new bug thread with a test case. Thanks. I'm not seeing anything using the test case presented in this thread against 3.3.x.

devtig
3 Jan 2011, 12:31 PM
Max_nl, and post a link to the new bug thread.