2011-07-06 19 views
4

ExtJS4網格預計每列適當的編輯器(cellEditor的或rowEditor)。 如果某個列的標題字段爲dateField - 日期選擇器將應用於該列中的每一行。extjs4格 - 改變每行的基礎上編輯列

我需要的是每行不同領域的編輯,而不是每列的編輯器。

的Extjs3解決方案提供here - 遺憾的是不適合在Extjs4情況。 (請檢查鏈接查看說明圖片,導致我不能發表圖片還)

還有被稱爲property grid單列的解決方案,但再次 - 它僅支持一列,很從EXT標準偏差。網格組件

我曾嘗試通過定製column.field和重裝grid.editingPlugin.editor手動更改網格編輯,但總是沒有領域空白rowEditor面板。

//by default rowEditor applies textField to all cells - I'm trying to force custom numberFiled on apropriate row 
var numberField=Ext.form.field.Number(); 
grid.columns[0].field=numberField; 
//destroy current rowEditor's instance 
delete grid.editingPlugin.editor; 
//now, upon doubleClick on apropriate cell it should reinitialize itself (initEditor()) - and it does, but is an empty panel 

我在這裏錯過了什麼?一旦我刪除editingPlugin.editor一切都像第一次rowEditor期間應從頭開始叫,但它失去所有的字段

+0

沒關係,我自己做到了: [鏈接](http://www.sencha.com/forum/showthread.php?139440-changing-columnEditor-per -ROW-基礎&P = 624107#post624107) – FlegmatoidZoid

回答

4

解決方案的Ext4:

我一直在尋找一個解決方案,並這傢伙說屬性網格有這種行爲。 我已經適應了它在一個乾淨的方式爲我工作 上initComponent我宣佈:

this.editors = { 
'date' : Ext.create('Ext.grid.CellEditor', { field: Ext.create('Ext.form.field.Date', {selectOnFocus: true})}), 
'string' : Ext.create('Ext.grid.CellEditor', { field: Ext.create('Ext.form.field.Text', {selectOnFocus: true})}), 
'number' : Ext.create('Ext.grid.CellEditor', { field: Ext.create('Ext.form.field.Number', {selectOnFocus: true})}), 
'int' : Ext.create('Ext.grid.CellEditor', { field: Ext.create('Ext.form.field.Number', {selectOnFocus: true})}), 
'boolean' : Ext.create('Ext.grid.CellEditor', { field: Ext.create('Ext.form.field.ComboBox', { 
    editable: false, 
    store: [[ true, 'Sim' ], [false, 'Não' ]] 
})}) 
}; 

我使用這些功能來幫我(複製):

this.renderCell = function(val, meta, rec) { 
    var result = val; 
    if (Ext.isDate(val)) { 
     result = me.renderDate(val); 
    } else if (Ext.isBoolean(val)) { 
     result = me.renderBool(val); 
    } 
    return Ext.util.Format.htmlEncode(result); 
}; 

this.getCellEditor = function(record, column) { 
    return this.editors[record.get('type')]; 
}; 

最後,這些功能相關聯到列:

{text: "Valor", name : 'colunaValor', width: 75, sortable: true, dataIndex: 'valor', width:200, 
    renderer: Ext.Function.bind(this.renderCell, this), 
    getEditor: Ext.Function.bind(this.getCellEditor, this) 
}