将已编辑的记录保存在单元格编辑网格中 [英] Saving edited record in a cell editing grid

查看:67
本文介绍了将已编辑的记录保存在单元格编辑网格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何单击保存按钮保存已编辑的记录?

How can I save the edited record on click of the save button?

我的代码:

// create the Data Store
var store = Ext.create('Ext.data.Store', {
    //autoSync: true,
    autoLoad:true,
    autoDestroy: true,
    url: 'update_premise.php',
    model: 'Plant',
    proxy: {
        type: 'ajax',
        // load remote data using HTTP
        url: 'getLab.php',
        // specify a XmlReader (coincides with the XML format of the returned data)
        reader: {
            type: 'json'
        },
          writer: {
            type: 'json'

        }
    },
    sorters: [{
        property: 'lab_name',
        direction:'ASC'
    }]
});

var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 1
});

// create the grid and specify what field you want
// to use for the editor at each header.
var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    columns: [{
        id: 'lab_name',
        header: 'Common Name',
        dataIndex: 'lab_name',
        flex: 1,
        editor: {
            allowBlank: false
        }
    }],
    selModel: {
        selType: 'cellmodel'
    },
    renderTo: 'editor-grid',
    width: 600,
    height: 300,
    title: 'Lab?',
    frame: true,
    tbar: [
     {
         text: 'Save',
         handler: function ()
         {
               for (var i = 0; i <grid.store.data.items.length; i++) {
                 var record = grid.store.data.items [i];
                 if (record.dirty) {
                 }
             }
         }
     }
     ],
    plugins: [cellEditing]
});

推荐答案

您不需要通过ajax调用进行保存,sencha会为您进行所有检查和保存.

You don't need to save via ajax calls sencha does all the checking and saving for you.

 for (var i = 0; i <grid.store.data.items.length; i++) {
        var record = grid.store.data.items [i];
        if (record.dirty) {
            ...
        }
 }

此部分可以替换为store.sync();

http://docs .sencha.com/extjs/4.2.1/#!/api/Ext.data.AbstractStore-method-sync

如果您想发送数据以更新到另一个url,则可以通过读取一个api对象来配置您的代理,而该api对象只是一个url参数.

If you want to send the data to update to another url then to read you can configure your proxy with an api object in staid of a single url parameter.

proxy: {
    type: 'ajax',
    api: {
        read    : 'getLab.php',
        create  : 'setLab.php',
        update  : 'setLab.php',
        destroy : 'deleteLab.php'
    }
    reader: {
        type: 'json'
    },
    writer: {
        type: 'json'

    }
}

这篇关于将已编辑的记录保存在单元格编辑网格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆