从 ExtJS 中的 GridPanel 获取模型

发布于 2025-01-05 17:49:50 字数 1446 浏览 3 评论 0原文

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

我相信 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
            }
        }
    });
},

感谢您的帮助!

I have a gridpanel that allows inline editing of a column. This column uses a combobox as the editor, and neither the "change" event nor the "select" event give me something usable to backtrace the edited value to get the changed row from the gridpanel.

I believe Ext floats the editor's combobox so therefore I can't do something simple like

combo.up()

To return to the grid.

Here is the grid panel from the view:

{
    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
    })]
}

Here is the controller code pertaining to this:

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
            }
        }
    });
},

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

儭儭莪哋寶赑 2025-01-12 17:49:50

您可以监控商店的 更新事件。

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

You can monitor store's update event.

init: function () {
    this.getMyimpprojectsStore().on('update', function(store, record) {
        // do something with record
    });
    // ...
},
玩物 2025-01-12 17:49:50

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

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

Try putting the listener on the CellEditing plugin. There are events for beforeedit, edit, and validateedit that receive an object containing references to the grid, the record, field, row and column indexes, and more. You should be able to check for the combobox in the event handler and handle your information from there.

Quick link to the doc page: Ext.grid.plugin.CellEditing

沧桑㈠ 2025-01-12 17:49:50

我确信更新插件将通过底层存储的 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”

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

I'm convinced that the update plugin will handle the update automatically, through the api of the underlying store and post the data automatically to the server if the proxy as autoSync to true.

Example of the configured proxy:

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
            });
        }
    }
}

});

I would look specially for the two configs: "autoSync" and "batchActions"

Hope this helps you further with your issue!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文