2010-08-16 19 views
0

我一直在努力創建一個EditorGridPanel供多個地址使用,沒有太多的成功。看到的情況是,客戶希望將地址位分開存儲,但格式化爲標準地址。因此,用於地址輸入的一般textarea和具有完全離散的字段方法都已經出來了。擴展CompositeField以在EditorGridPanels中使用?

這就是CompositeField發揮作用的地方。我一直在擴展Column和Composite字段,讓編輯以所需的方式工作。它已經到了它種類的作品(它顯示,如果你點擊它足夠),但會拋出錯誤「this.ownerCt是未定義的」。從一些Google搜索中,我發現這是一個事件實例化順序的問題,但我不確定如何在保持其封裝的同時實例化編輯器。

代碼:

Framework.AddressEditorField = Ext.extend(Ext.form.CompositeField,{ 
    initComponent: function() { 
     Ext.apply(this,{ 
      items:[ 
       {name:'test',xtype:'textfield',width:50}, 
       {name:'test2',xtype:'textfield',width:50} 
      ] 
     }); 
     Framework.AddressEditorField.superclass.initComponent.apply(this); 
    } 
}); 

Framework.AddressEditor = Ext.extend(Ext.grid.Column,{ 
    width:220, 
    editable:true, 
    constructor: function(cfg) { 
     this.editor = new Framework.AddressEditorField(); 
     Framework.AddressEditor.superclass.constructor.call(this, cfg); 
     this.text=""; 
     if(!this.id){ 
      this.id = Ext.id(); 
     } 
     this.renderer = this.renderer.createDelegate(this); 
    }, 
    init : function(grid){ 
     this.grid = grid; 

    }, 

    renderer : function(v, p, record){ 
     p.css += ' x-grid3-address-col-td'; 
     var template = new Ext.XTemplate("<pre class='{0}'><tpl if='careof!=\"\"'>{careof}\n</tpl>{address1}\n<tpl if='address2!=\"\"'>{address2}\n</tpl>{city}, {state} {zip}<tpl if='country!=\"\">\n{country}</tpl></pre>") 
     var t = template.applyTemplate(record.data); 
     return String.format(t, this.createId()); 
    }, 

    createId : function(){ 
     return 'x-grid3-cc-' + this.id; 
    } 
}); 

而且EditorGridPanel的相關章節:

{xtype:'fieldset',itemId:'mailGridFieldset',title:'Addresses',items:{ 
        xtype:'editorgrid', 
        unstyled:true, 
        itemId:'mailGrid', 
        hideHeaders:true, 
        autoHeight:true, 
        width:450, 
        clicksToEdit:1, 
        defaultMailType:'Home', 
        store:this.addressStore, 
        border: false, 
        columns:[ 
         { 
          editable:true,dataIndex:'address_type',editor:combo,renderer:Ext.util.Format.comboRenderer(combo) 
         }, 
         new Framework.AddressEditor(), 
         defaultBoxMailing 
        ], 
        sm:new Ext.grid.RowSelectionModel() 
       }} 

我敢肯定,我其實這樣做十分錯誤的考慮我還沒有發現,延長許多例子CompositeField或Column。任何智慧的話語?

謝謝。

回答

0

只需繞過它,並在單元格單擊顯示一個模式窗口,其中用戶可以輸入/編輯數據的窗體。

+0

這是我的替代解決方案,如果我不能讓它按我希望的方式工作。你是說我要去做什麼是不可能的? – 2010-08-17 16:17:36

+0

我不是說這是不可能的。我不知道,但在我看來,即使它是,它可能真的很黑。我所說的是:保持簡單 – Mchl 2010-08-17 16:39:13