2
* Ext JS Library 3.0 RC2
3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.grid.PropertyRecord
11
* A specific {@link Ext.data.Record} type that represents a name/value pair and is made to work with the
12
* {@link Ext.grid.PropertyGrid}. Typically, PropertyRecords do not need to be created directly as they can be
13
* created implicitly by simply using the appropriate data configs either via the {@link Ext.grid.PropertyGrid#source}
14
* config property or by calling {@link Ext.grid.PropertyGrid#setSource}. However, if the need arises, these records
15
* can also be created explicitly as shwon below. Example usage:
17
var rec = new Ext.grid.PropertyRecord({
19
value: new Date(Date.parse('05/26/1972'))
21
// Add record to an already populated grid
22
grid.store.addSorted(rec);
25
* @param {Object} config A data object in the format: {name: [name], value: [value]}. The specified value's type
26
* will be read automatically by the grid to determine the type of editor to use when displaying it.
28
Ext.grid.PropertyRecord = Ext.data.Record.create([
29
{name:'name',type:'string'}, 'value'
33
* @class Ext.grid.PropertyStore
34
* @extends Ext.util.Observable
35
* A custom wrapper for the {@link Ext.grid.PropertyGrid}'s {@link Ext.data.Store}. This class handles the mapping
36
* between the custom data source objects supported by the grid and the {@link Ext.grid.PropertyRecord} format
37
* required for compatibility with the underlying store. Generally this class should not need to be used directly --
38
* the grid's data should be accessed from the underlying store via the {@link #store} property.
40
* @param {Ext.grid.Grid} grid The grid this store will be bound to
41
* @param {Object} source The source data config object
43
Ext.grid.PropertyStore = function(grid, source){
45
this.store = new Ext.data.Store({
46
recordType : Ext.grid.PropertyRecord
48
this.store.on('update', this.onUpdate, this);
50
this.setSource(source);
52
Ext.grid.PropertyStore.superclass.constructor.call(this);
54
Ext.extend(Ext.grid.PropertyStore, Ext.util.Observable, {
55
// protected - should only be called by the grid. Use grid.setSource instead.
56
setSource : function(o){
58
this.store.removeAll();
61
if(this.isEditableValue(o[k])){
62
data.push(new Ext.grid.PropertyRecord({name: k, value: o[k]}, k));
65
this.store.loadRecords({records: data}, {}, true);
69
onUpdate : function(ds, record, type){
70
if(type == Ext.data.Record.EDIT){
71
var v = record.data['value'];
72
var oldValue = record.modified['value'];
73
if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
74
this.source[record.id] = v;
76
this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
84
getProperty : function(row){
85
return this.store.getAt(row);
89
isEditableValue: function(val){
92
}else if(typeof val == 'object' || typeof val == 'function'){
99
setValue : function(prop, value){
100
this.source[prop] = value;
101
this.store.getById(prop).set('value', value);
104
// protected - should only be called by the grid. Use grid.getSource instead.
105
getSource : function(){
111
* @class Ext.grid.PropertyColumnModel
112
* @extends Ext.grid.ColumnModel
113
* A custom column model for the {@link Ext.grid.PropertyGrid}. Generally it should not need to be used directly.
115
* @param {Ext.grid.Grid} grid The grid this store will be bound to
116
* @param {Object} source The source data config object
118
Ext.grid.PropertyColumnModel = function(grid, store){
121
g.PropertyColumnModel.superclass.constructor.call(this, [
122
{header: this.nameText, width:50, sortable: true, dataIndex:'name', id: 'name', menuDisabled:true},
123
{header: this.valueText, width:50, resizable:false, dataIndex: 'value', id: 'value', menuDisabled:true}
126
this.bselect = Ext.DomHelper.append(document.body, {
127
tag: 'select', cls: 'x-grid-editor x-hide-display', children: [
128
{tag: 'option', value: 'true', html: 'true'},
129
{tag: 'option', value: 'false', html: 'false'}
134
var bfield = new f.Field({
136
bselect : this.bselect,
138
getValue : function(){
139
return this.bselect.value == 'true';
143
'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
144
'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
145
'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
146
'boolean' : new g.GridEditor(bfield)
148
this.renderCellDelegate = this.renderCell.createDelegate(this);
149
this.renderPropDelegate = this.renderProp.createDelegate(this);
152
Ext.extend(Ext.grid.PropertyColumnModel, Ext.grid.ColumnModel, {
153
// private - strings used for locale support
156
dateFormat : 'm/j/Y',
159
renderDate : function(dateVal){
160
return dateVal.dateFormat(this.dateFormat);
164
renderBool : function(bVal){
165
return bVal ? 'true' : 'false';
169
isCellEditable : function(colIndex, rowIndex){
170
return colIndex == 1;
174
getRenderer : function(col){
176
this.renderCellDelegate : this.renderPropDelegate;
180
renderProp : function(v){
181
return this.getPropertyName(v);
185
renderCell : function(val){
188
rv = this.renderDate(val);
189
}else if(typeof val == 'boolean'){
190
rv = this.renderBool(val);
192
return Ext.util.Format.htmlEncode(rv);
196
getPropertyName : function(name){
197
var pn = this.grid.propertyNames;
198
return pn && pn[name] ? pn[name] : name;
202
getCellEditor : function(colIndex, rowIndex){
203
var p = this.store.getProperty(rowIndex);
204
var n = p.data['name'], val = p.data['value'];
205
if(this.grid.customEditors[n]){
206
return this.grid.customEditors[n];
209
return this.editors['date'];
210
}else if(typeof val == 'number'){
211
return this.editors['number'];
212
}else if(typeof val == 'boolean'){
213
return this.editors['boolean'];
215
return this.editors['string'];
220
destroy : function(){
221
Ext.grid.PropertyColumnModel.superclass.destroy.call(this);
222
for(var ed in this.editors){
229
* @class Ext.grid.PropertyGrid
230
* @extends Ext.grid.EditorGridPanel
231
* A specialized grid implementation intended to mimic the traditional property grid as typically seen in
232
* development IDEs. Each row in the grid represents a property of some object, and the data is stored
233
* as a set of name/value pairs in {@link Ext.grid.PropertyRecord}s. Example usage:
235
var grid = new Ext.grid.PropertyGrid({
236
title: 'Properties Grid',
241
"(name)": "My Object",
242
"Created": new Date(Date.parse('10/15/2006')),
245
"Description": "A test object"
250
* @param {Object} config The grid config object
252
Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, {
254
* @cfg {Object} propertyNames An object containing property name/display name pairs.
255
* If specified, the display name will be shown in the name column instead of the property name.
258
* @cfg {Object} source A data object to use as the data source of the grid (see {@link #setSource} for details).
261
* @cfg {Object} customEditors An object containing name/value pairs of custom editor type definitions that allow
262
* the grid to support additional types of editable fields. By default, the grid supports strongly-typed editing
263
* of strings, dates, numbers and booleans using built-in form editors, but any custom type can be supported and
264
* associated with a custom input control by specifying a custom editor. The name of the editor
265
* type should correspond with the name of the property that will use the editor. Example usage:
267
var grid = new Ext.grid.PropertyGrid({
270
'Start Time': new Ext.grid.GridEditor(new Ext.form.TimeField({selectOnFocus:true}))
273
'Start Time': '10:00 AM'
279
// private config overrides
280
enableColumnMove:false,
282
trackMouseOver: false,
284
enableHdMenu : false,
290
initComponent : function(){
291
this.customEditors = this.customEditors || {};
292
this.lastEditRow = null;
293
var store = new Ext.grid.PropertyStore(this);
294
this.propStore = store;
295
var cm = new Ext.grid.PropertyColumnModel(this, store);
296
store.store.sort('name', 'ASC');
299
* @event beforepropertychange
300
* Fires before a property value changes. Handlers can return false to cancel the property change
301
* (this will internally call {@link Ext.data.Record#reject} on the property's record).
302
* @param {Object} source The source data object for the grid (corresponds to the same object passed in
303
* as the {@link #source} config property).
304
* @param {String} recordId The record's id in the data store
305
* @param {Mixed} value The current edited property value
306
* @param {Mixed} oldValue The original property value prior to editing
308
'beforepropertychange',
310
* @event propertychange
311
* Fires after a property value has changed.
312
* @param {Object} source The source data object for the grid (corresponds to the same object passed in
313
* as the {@link #source} config property).
314
* @param {String} recordId The record's id in the data store
315
* @param {Mixed} value The current edited property value
316
* @param {Mixed} oldValue The original property value prior to editing
321
this.ds = store.store;
322
Ext.grid.PropertyGrid.superclass.initComponent.call(this);
324
this.mon(this.selModel, 'beforecellselect', function(sm, rowIndex, colIndex){
326
this.startEditing.defer(200, this, [rowIndex, 1]);
333
onRender : function(){
334
Ext.grid.PropertyGrid.superclass.onRender.apply(this, arguments);
336
this.getGridEl().addClass('x-props-grid');
340
afterRender: function(){
341
Ext.grid.PropertyGrid.superclass.afterRender.apply(this, arguments);
343
this.setSource(this.source);
348
* Sets the source data object containing the property data. The data object can contain one or more name/value
349
* pairs representing all of the properties of an object to display in the grid, and this data will automatically
350
* be loaded into the grid's {@link #store}. The values should be supplied in the proper data type if needed,
351
* otherwise string type will be assumed. If the grid already contains data, this method will replace any
352
* existing data. See also the {@link #source} config value. Example usage:
355
"(name)": "My Object",
356
"Created": new Date(Date.parse('10/15/2006')), // date type
357
"Available": false, // boolean type
358
"Version": .01, // decimal type
359
"Description": "A test object"
362
* @param {Object} source The data object
364
setSource : function(source){
365
this.propStore.setSource(source);
369
* Gets the source data object containing the property data. See {@link #setSource} for details regarding the
370
* format of the data object.
371
* @return {Object} The data object
373
getSource : function(){
374
return this.propStore.getSource();
377
Ext.reg("propertygrid", Ext.grid.PropertyGrid);