2012-02-14 57 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