2013-12-16 122 views
3

如何添加属性网格内的列?到目前为止,我已经试过如下:Ext.js将列添加到属性网格

source : dataForGrid.source, 
columns : [ 
      { 
       text: 'text', 
       xtype : 'checkcolumn', 
       dataIndex : 'status', 
       width : 100, 
       editor : { 
        xtype : 'checkbox' 
       }, 
       listeners : { 
        checkchange : function (checkColumn, rowIndex, checked, eOpts) { 
         //some code here 
        } 
       }, 
       renderer: function(val, m, rec, rowIndex) { 
        //some code here 
       } 
      }, 
      { 
       text: 'TEST', 
       sortable: false, 
       dataIndex: 'value2', 
       field: { 
        xtype: 'textfield' 
       } 
      } 
     ], 
customEditors: dataForGrid.customEditors, 

我的来源是非常标准的,我有一个TEMPOBJ女巫持有以下特性(dataForGrid被传递到电网的来源属性):

tempObj.name = data[i].some; 
     tempObj.text = data[i].some === '' ? '' : '<a class="clientNameTextSomeGrid" onclick="console.log(123)">' + data[i].some + '</a>'; 
     tempObj.editor = data[i].someother; 
     tempObj.datatype = 'nvarchar'; 
     tempObj.editable = true; 
     tempObj.status = data[i].someother === 'A' ? true : false; 
     tempObj.renderer = ""; 
     tempObj.value2 = "gcgrg"; 
dataForGrid.source.push(tempObj); 

,我有一个customEditors:

var newField = Ext.create('Ext.form.ComboBox', { 
      name: data[i].some, 
      store: tempStore, 
      clientID: tempObj.editor, 
      queryMode: 'local', 
      editable: false, 
      displayField: 'value', 
      valueField: 'id', 
      triggerAction: 'all' 
     }); 
dataForGrid.customEditors[data[i].some] = new Ext.grid.CellEditor({ 
      field: newField 
     }); 

复选框(和使用customEditors组合框)工作正常。但是我无法为'TEST'列添加值(该列出现但没有值)。任何帮助将不胜感激。如果您有任何问题或需要更多代码,请在下面写下评论并提供。

* UPDATE:如果我的第二列的dataIndex属性保存的是“状态”的值(从TEMPOBJ),列呈现与具体数值,但如果我再次,使用Value 2属性从TEMPOBJ列保持空白。

+1

有趣的问题,只有改善将是一个的jsfiddle – roo2

回答

0

,我们做到了这一点被扩展模型的方式:

Ext.define('Ext.ux.grid.property.Property', { 
    extend: 'Ext.data.Model', 
    idProperty: 'name', 
    fields: [ 
     { 
      name: 'name', 
      type: 'string' 
     }, 
     { 
      name: 'text', 
      type: 'string' 
     }, 
     { 
      name: 'value' 
     }, 
     { 
      name: 'editor' // custom editor 
     }, 
     { 
      name: 'group', // for grouping 
      type: 'string' 
     }, 
     { 
      name: 'editable', 
      type: 'boolean', 
      defaultValue: true 
     }, 
     { 
      name: 'status', 
      type: 'boolean' 
     }, 
     { 
      name: 'renderer', // custom renderer 
      defaultValue: null 
     }, 
     ////////////////////////////////////// 
     // custom fields begin here 
     // Custom Properties grid 
     { 
      name: 'someName', 
      type: 'string' 
     } 
    ] 
}); 

,然后将源变成了:

tempObj.name = data[i].some; 
    tempObj.text = data[i].some === '' ? '' : '<a class="clientNameTextSomeGrid" onclick="console.log(123)">' + data[i].some + '</a>'; 
    tempObj.editor = data[i].someother; 
    tempObj.datatype = 'nvarchar'; 
    tempObj.editable = true; 
    tempObj.status = data[i].someother === 'A' ? true : false; 
    tempObj.renderer = ""; 
    tempObj.someName = "Something in here"; 
dataForGrid.source.push(tempObj);