动态编辑数据(网格json Ext JS 4)

时间:2013-05-27 18:53:38

标签: php mysql json extjs grid

我有这么简单的问题,但找不到答案(文件)。我创建了Grid,从 MySQL 数据库中检索信息。使用 Ext JS 4.2 。 我们来看看剧本......

Ext.define("AppStore",{
    extend: "Ext.data.Model",
    fields: [
        {name: "nickname" , type: "auto"},
        {name: "email"    , type: "auto"}
    ]
});

var store = Ext.create("Ext.data.Store",{
    model: "AppStore",
    proxy: {
        type: "ajax",
        api: {
            read    : "./read.php",
            update  : "./update.php"
        },
        reader: {
            type: "json",
            root: ""
        },
        writer: {
            type: "json",
            writeAllFields: true,
            encode: false,
            root: ""
        }
    },
    listeners: {
        read: function(operation, callback, scope){

        },
        update: function(operation, callback, scope){
            // Do I have to do something from here ?
        }
    },
    autoLoad: true
});

Ext.create("Ext.grid.Panel",{
    store: store,
    selMode: "cellmodel",
    columns: [
        {
            text: "Nickname",
            flex: 1,
            dataIndex: "nickname",
            editor: {
                xtype: "textfield",
                allowBlank: false
            }
        },
        {
            text: "Email",
            flex: 1.5,
            dataIndex: "email",
            editor: {
                xtype: "textfield",
                allowBlank: false
            }
        }
    ],
    plugins: [
        Ext.create("Ext.grid.plugin.CellEditing",{
            clicksToEdit: 2
        })
    ]
});

一切都运行正常,只关心我如何在网格单元格中更改数据后向 MySQL 发送更新数据的请求。任何示例,文档或如何完成此任务的方式将不胜感激,谢谢......

1 个答案:

答案 0 :(得分:1)

通常,您需要在网格商店中调用sync(),以便将模型更改保留到服务器。这可以配置为在每次编辑时自动发生(请参阅商店的autoSync property)。但是,我建议最好根据某些特定操作处理sync()调用(例如,点击“保存”按钮等)。