如何从网格获取值并发布它们。扩展JS

时间:2019-01-16 08:44:15

标签: javascript extjs extjs4 extjs6 extjs6-modern

我对网格中的getValues感兴趣,并使用网格的自定义编辑表单上的按钮confirm将其发布。

但是我不知道如何getValues()。我不能使用它,否则会导致在“ fieldset” xtype中完成值。

如何获取网格值...可能存在某种方法,该方法允许将grideditable插件配置设置为Ajax请求配置参数?

我的代码的一部分:

Ext.define('Foresto.model.EditListRenters', {
            extend: 'Ext.grid.Grid',
            xtype: 'rentlist',
            requires: [
                'Ext.grid.plugin.Editable',
                'Foresto.model.RentsListModel'
            ],
            store: {
                model: 'Foresto.model.RentsListModel',
                autoLoad: true,
                pageSize: 0,
                proxy: {
                    type: 'ajax',
                    url: '/myownurl',
                    reader: {
                        type: 'json',
                        rootProperty: 'results'
                    }

                }
            },
            plugins: [{
                type: 'grideditable',
                triggerEvent: 'doubletap',
                enableDeleteButton: true,
                formConfig: null,

                defaultFormConfig: {
                    xtype: 'formpanel',
                    title: 'Редактировать договор',
                    scrollable: true,
                    items: {
                        xtype: 'fieldset'
                    }
                },

                toolbarConfig: {
                    xtype: 'titlebar',
                    cls: 'hdr2',
                    height: 46.63,
                    docked: 'top',
                    items: [{
                        xtype: 'button',
                        ui: 'decline',
                        cls: 'grbuttons',
                        text: 'cancel',
                        align: 'left',
                        action: 'cancel'
                    }, {
                        xtype: 'button',
                        ui: 'confirm',
                        cls: 'grbuttons',
                        text: 'submit',
                        align: 'right',
                        action: 'submit',
                        handler: function() {

                            var rentset = _.getValues() //how get values??



                            Ext.Ajax.request({
                                url: '/myownurl/contract/',
                                method: 'POST',
                                params: rentset
                            })
                        }
                    }]
                }

            }],
            columns: [ //my columns]
  });

2 个答案:

答案 0 :(得分:2)

Extjs使用MVC模式,因此您不需要手动挖掘更改的值。您的数据记录(干净的和脏的)已存储,连接由代理管理。 Grid只是用于可视化数据的可视组件,其插件是更改数据的助手。

不要(重新)在函数内部创建新请求,但要告诉商店来完成这项工作:

handler: function () {
    form.updateRecord();
    form.hide();
    grid.getStore().sync();
}

还要指定代理参数:

proxy: {
    type: 'ajax',
    batchActions: true,
    url: './myownurl',
    actionMethods: {
        create: 'POST',
        read: 'POST',
        update: 'POST',
        destroy: 'POST'
    },
    reader: {
        type: 'json',
        rootProperty: 'results'
    },
    writer: {
        type: 'json',
        root: 'data',
        encode: true,
        writeAllFields: true,
    }
}

答案 1 :(得分:0)

使用

获取修改的记录
grid.getStore().getModifiedRecords();

获取自上次提交以来添加或更新的所有记录。