2012-02-14 59 views
0

我有一個允許內聯編輯列的網格面板。此列使用組合框作爲編輯器,並且「change」事件和「select」事件都不會爲我提供可回溯編輯值的內容,以從gridpanel獲取已更改的行。從GridPanel在ExtJS中獲取模型

我相信分機浮動編輯的組合框所以因此我不能做一些簡單的像

combo.up() 

要返回到電網。

下面是從視圖中的網格面板:

{ 
    xtype: 'gridpanel', 
    title: 'Important Projects', 
    id: 'importantProjectsGrid', 
    dockedItems: [], 
    flex: 1, 
    columns: [ 
     { header: 'Quote Name', dataIndex: 'QuoteName', flex: 4 }, 
     { header: 'Quote Status', dataIndex: 'QuoteStatusID', flex: 6, editor: { 
      xtype: 'combobox', 
      editable: false, 
      action: 'QuoteStatus', 
      selectOnTab: true, 
      store: 'statuses', 
      queryMode: 'local', 
      displayField: 'Description', 
      valueField: 'Description' 
     } } 
    ], 
    store: 'myimpprojects', 
    selModel: { 
     selType: 'cellmodel' 
    }, 
    plugins: [Ext.create('Ext.grid.plugin.CellEditing', { 
     clicksToEdit: 1 
    })] 
} 

下面是關於這個控制器代碼:

init: function() { 
    this.control({ 
     '[action=QuoteStatus]': { 
      change: function (combo, new_value, old_value, opts) { 
       // I need to go back up from this combobox 
       // to get the row that this value was edited in 
       // to grab an ID value from that row's data 
       // in order to make an ajax request 
      } 
     } 
    }); 
}, 

感謝您的幫助!

回答

1

嘗試將監聽器放在CellEditing插件上。有接收包含對網格,記錄,字段,行和列索引等的引用的對象的beforeediteditvalidateedit的事件。您應該能夠檢查事件處理程序中的組合框,並從那裏處理您的信息。

快速鏈接到文檔頁面:Ext.grid.plugin.CellEditing

+0

謝謝你回答,這是我尋找的東西 – thinkdevcode 2012-02-14 19:58:56

2

您可以監視商店的update事件。

init: function() { 
    this.getMyimpprojectsStore().on('update', function(store, record) { 
     // do something with record 
    }); 
    // ... 
}, 
1

我相信,在更新插件會自動處理更新,通過底層存儲的API,並自動發佈數據到服務器,如果代理的自動同步爲true。所配置的代理的

實施例:

Ext.define('MyApp.store.YourStore', { 
extend: 'Ext.data.Store', 

model: 'MyApp.model.YourGridModel', 
autoSync: true, //Commits the changes realtime to the server 
proxy: { 
    type: 'ajax', 
    batchActions : true, //Commits the changes everytime a value is changed if true o otherwise store the changes and batch update them in 1 single post 
    api: { 
     read: 'path/to/select', 
     create: 'path/to/create', 
     update: 'path/to/update', 
     destroy: 'path/to/delete' 
    }, 
    reader: { 
     type: 'json', 
     root: 'results', 
     successProperty: 'success' 
    }, 
    writer: { 
     type: 'json', 
     writeAllFields: true 
    }, 
    listeners: { 
     exception: function(proxy, response, operation){ 

      Ext.MessageBox.show({ 
       title: 'REMOTE EXCEPTION', 
       msg: operation.getError(), 
       icon: Ext.MessageBox.ERROR, 
       buttons: Ext.Msg.OK 
      }); 
     } 
    } 
}, 
listeners: { 
    write: function(proxy, operation){ 

     var response = Ext.JSON.decode(operation.response.responseText); 

     if(response.success == true) 
     {   
      //TODO: Proxy - Messageboxes might be a little anoying we might instead use the status bar in teh grid or something so show status of the operation 
      Ext.MessageBox.show({ 
       title: this.xFileLibraryTitle, 
       msg: response.message, 
       icon: (response.success == true)? Ext.MessageBox.INFO : Ext.MessageBox.ERROR, 
       buttons: Ext.Msg.OK 
      }); 
     } 
    } 
} 

});

我會找專門爲兩個CONFIGS:「自動同步」和「batchActions」

希望這有助於進一步您解決問題!

+0

謝謝你的答案,但我不使用代理服務器來更新/刪除數據。我手動使用ajax請求。再次感謝 – thinkdevcode 2012-02-14 19:57:33

+0

這很好,儘管我認爲使用代理可以獲得更多價值......但是您可能會運行一些特殊的場景,您希望完全控制每一步,那就沒問題了!乾杯! – 2012-02-15 10:36:03