从ExtJS中的GridPanel获取模型

时间:2012-02-14 17:30:19

标签: javascript extjs combobox extjs4 gridpanel

我有一个允许内联编辑列的网格面板。此列使用组合框作为编辑器,“更改”事件和“选择”事件都没有为我提供可用于回溯编辑值以从网格面板获取更改行的内容。

我相信Ext会浮动编辑器的组合框,因此我不能做像

那样简单的事情
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
            }
        }
    });
},

感谢您的帮助!

3 个答案:

答案 0 :(得分:2)

您可以监控商店的update事件。

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

答案 1 :(得分:1)

我确信更新插件会自动处理更新,通过底层商店的api自动将数据发布到服务器,如果代理为autoSync为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
            });
        }
    }
}

});

我会特意看两个配置:“autoSync”和“batchActions”

希望这可以帮助您进一步解决问题!

答案 2 :(得分:1)

尝试将侦听器放在CellEditing插件上。有beforeediteditvalidateedit的事件接收包含对网格,记录,字段,行和列索引等的引用的对象。您应该能够在事件处理程序中检查组合框并从那里处理您的信息。

指向文档页面的快速链接:Ext.grid.plugin.CellEditing

相关问题