PDA

View Full Version : PropertyGrid colModel fixed



Monkee
17 Nov 2010, 5:49 AM
If the ColumnModel for your PropertyGrid is not working as expected (setting the widths for columns or changing the header texts), this code could be useful:


(function() {

var originalInit = Ext.grid.PropertyGrid.prototype.initComponent;

Ext.override(Ext.grid.PropertyGrid, {

initComponent: function() {

this.customRenderers = this.customRenderers || {};
this.customEditors = this.customEditors || {};
this.lastEditRow = null;
var store = new Ext.grid.PropertyStore(this);
this.propStore = store;

var cm = new Ext.grid.PropertyColumnModel(this, store);
// the fix
cm.setConfig(cm.grid.initialConfig.cm);

store.store.sort('name', 'ASC');
this.addEvents(

/**
* @event beforepropertychange
* Fires before a property value changes. Handlers can return false to cancel the property change
* (this will internally call {@link Ext.data.Record#reject} on the property's record).
* @param {Object} source The source data object for the grid (corresponds to the same object passed in
* as the {@link #source} config property).
* @param {String} recordId The record's id in the data store
* @param {Mixed} value The current edited property value
* @param {Mixed} oldValue The original property value prior to editing
*/
'beforepropertychange',

/**
* @event propertychange
* Fires after a property value has changed.
* @param {Object} source The source data object for the grid (corresponds to the same object passed in
* as the {@link #source} config property).
* @param {String} recordId The record's id in the data store
* @param {Mixed} value The current edited property value
* @param {Mixed} oldValue The original property value prior to editing
*/
'propertychange'
);
this.cm = cm;
this.ds = store.store;
Ext.grid.PropertyGrid.superclass.initComponent.call(this);

this.mon(this.selModel, 'beforecellselect', function(sm, rowIndex, colIndex){
if(colIndex === 0){
this.startEditing.defer(200, this, [rowIndex, 1]);
return false;
}
}, this);

}
});

})();