PDA

View Full Version : [DEFER] Custom grid column with width and/or sortable



Condor
16 Aug 2010, 5:29 AM
From this thread (http://www.sencha.com/forum/showthread.php?107097-Problem-with-extending-Ext.Action&p=501612#post501612):
When specifying a column as an xtype it is not possible to define 'width' and/or 'sortable' in the column class.

Example:

MyColumn = Ext.extend(Ext.grid.Column, {
constructor: function(config) {
MyColumn.superclass.constructor.call(this, Ext.apply({
header: 'ID',
width: 10,
sortable: true
}, config));
}
});
Ext.grid.Column.types['mycolumn'] = MyColumn;
var colModel = new Ext.grid.ColumnModel({
columns: [
{xtype: 'mycolumn'}
]
});
The resulting column will have width:100 (=defaultWidth) and sortable:false (=defaultSortable).

We could change:

Ext.override(Ext.grid.ColumnModel, {
setConfig : function(config, initial) {
var i, c, len;
if (!initial) {
delete this.totalWidth;
for (i = 0, len = this.config.length; i < len; i++) {
c = this.config[i];
if (c.setEditor) {
c.setEditor(null);
}
}
}
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 (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;
}
c = Ext.applyIf(config[i], this.defaults);
this.lookup[c.id] = c;
}
if (!initial) {
this.fireEvent('configchange', this);
}
}
});
But that would have impact on the config options passed to the column constructor, which wouldn't be backward compatible.

Jamie Avins
16 Aug 2010, 10:27 AM
Do to the impact this would have on existing applications we cannot add this to the 3.x branch. This should be possible with the new column modes in 4.x.