1 //<script type="text/javascript">
3 * @class Roo.form.GridField
4 * @extends Roo.form.Field
5 * Embed a grid (or editable grid into a form)
8 * Creates a new GridField
9 * @param {Object} config Configuration options
11 Roo.form.GridField = function(config){
12 Roo.form.GridField.superclass.constructor.call(this, config);
16 Roo.extend(Roo.form.GridField, Roo.form.Field, {
18 * @cfg {Number} width - used to restrict width of grid..
22 * @cfg {Number} height - used to restrict height of grid..
26 * @cfg {Object} xgrid (xtype'd description of grid) Grid or EditorGrid
30 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
31 * {tag: "input", type: "checkbox", autocomplete: "off"})
33 // defaultAutoCreate : { tag: 'div' },
34 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
36 * @cfg {String} addTitle Text to include for adding a title.
40 onResize : function(){
41 Roo.form.Field.superclass.onResize.apply(this, arguments);
44 initEvents : function(){
45 // Roo.form.Checkbox.superclass.initEvents.call(this);
51 getResizeEl : function(){
55 getPositionEl : function(){
60 onRender : function(ct, position){
62 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
63 var style = this.style;
66 Roo.form.DisplayImage.superclass.onRender.call(this, ct, position);
67 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
68 this.viewEl = this.wrap.createChild({ tag: 'div' });
70 this.viewEl.applyStyles(style);
73 this.viewEl.setWidth(this.width);
76 this.viewEl.setHeight(this.height);
78 //if(this.inputValue !== undefined){
79 //this.setValue(this.value);
82 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
86 this.grid.getDataSource().on('remove', this.refreshValue, this);
87 this.grid.getDataSource().on('update', this.refreshValue, this);
88 this.grid.on('afteredit', this.refreshValue, this);
94 * Sets the value of the item.
95 * @param {String} either an object or a string..
97 setValue : function(v){
99 v = v || []; // empty set..
100 // this does not seem smart - it really only affects memoryproxy grids..
101 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
102 var ds = this.grid.getDataSource();
103 // assumes a json reader..
105 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
108 Roo.form.GridField.superclass.setValue.call(this, v);
110 // should load data in the grid really....
114 refreshValue: function() {
116 this.grid.getDataSource().each(function(r) {
119 this.el.dom.value = Roo.encode(val);