View Full Version : ColumnModel.setConfig sets editor property to null

24 May 2010, 11:06 PM
I have the problem that after a call to ColumnModel.setConfig the editor properties of the columns are set to null. This thread has already been posted but I forgot to format the testcode. Thanks for any help!

Hi, is there a best practice to customize a grid programmatically?

I would like to set the following options in an existing edit grid:

order of columns

which columns to hide/display

column width

[sort direction]

My approach was to loop through the configured columns of the columnModel and create a new configuration array by copying+modifying the original columns. Then I set the new configuration via

grid.colModel.setConfig(newColumnConfig, false);

Unfortunately after the call the editor option of the columns is set to null which results in a non-editable grid. Before the call the columns in the configuration have a valid editor set. So it seems ExtJs sets the editors of the columns to null. But why? How can I customize it and still have it editable?

Thanks in advance.

Here is my test code:

function customizeGrid(grid) {

var columnData = [ { id: "price", width: 100, sort: 'ASC' },
{ id: "availDate", width: 200, sort: 'ASC' },
{ id: "light", width: 50, sort: 'DES' } ];

var newColumnConfig = new Array();
var index = 0;

// copy requested columns
for (var i = 0; i < columnData.length; i++) {

var column = grid.colModel.getColumnById(columnData[i].id);
if (column) {
// copy column to new configuration
newColumnConfig[index] = column;
// update
newColumnConfig[index].hidden = false;
newColumnConfig[index].width = columnData[i].width;

// set flag to indicate column is already copied
column.copied = true;

// copy remaining columns (hidden)
for (var i = 0; i < grid.colModel.config.length; i++) {

var column = grid.colModel.config[i];
if (!column.copied) {

newColumnConfig[index] = column;
newColumnConfig[index].hidden = true;

grid.colModel.setConfig(newColumnConfig, false);


24 May 2010, 11:14 PM
Here's the code you'll have to override.

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


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

c.id = i;
var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
c = new Cls(c);
config[i] = c;
this.lookup[c.id] = c;
this.fireEvent('configchange', this);

25 May 2010, 12:04 AM
Thanks for your reply. I am not sure though if overriding setConfig is really okay, since it would change the default behaviour (e.g. the origninal code calls destroy for each column). There may also be problems in the future when upgrading to another ExtJs version.
Is setting the editor to null in setConfig a bug then?
Isn't there another option to customize the grid with a new configuration (without loosing editability)?

Thank you.

25 May 2010, 12:10 AM
It's not a bug, it's just cleaning up before setting the new config (which might not include editors). To get editability with your new config, you'll need to create new editors (if you don't want to override the default behavior)