DOJO增强的DataGrid - 更新数据库 [英] DOJO Enhanced DataGrid - update database

查看:65
本文介绍了DOJO增强的DataGrid - 更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有一个如何使用DOJO增强的DataGrid编辑的信息更新数据库表的工作示例?我有一个postgresql数据库后端使用dojo.data.ItemFileWriteStore在echos json_encode(...)。

Does anyone have a working example of how to update a database table with edited information from DOJO Enhanced DataGrid? I have a postgresql database backend using dojo.data.ItemFileWriteStore which in echos json_encode(...).

<head>
<script type="text/javascript"> 
dojo.require("dojox.grid.EnhancedGrid");        
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojox.grid.enhanced.plugins.Pagination");
dojo.require("dojox.grid.enhanced.plugins.Filter");

dojo.addOnLoad(function() {
    // our test data store for this example:
    var jsonStore = new dojo.data.ItemFileWriteStore({
        url: 'queries/catalog_qry.php'
});

// set the layout structure:
var gridLayout = [{
    field: 'name_link',
    width: '30px'
},{
    field: 'name',
    name: 'Description',
    editable: 'true',
    width: 'auto'
},{
    field: 'quantity_owned',
    name: 'Quantity',
    width: '150px'
},{
    field: 'avg_unit_price',
    name: 'AVG Unit Price ($)',
    width: '150px'
        },{
    field: 'category',
    name: 'Category',
    width: '150px',
    editable: 'true',
    type: dojox.grid.cells.Select, 
    options: ['CFE', 'GFE', 'Other']
        }];

//plugins
var plugins = {
    pagination: true,
    filter: true
};

     // create a new grid:
        var grid1 = new dojox.grid.EnhancedGrid({
            id: 'grid',
    query: { name: '*' },
            store: jsonStore,
            structure: gridLayout,
    plugins: plugins,
    columnReordering: true,
    escapeHTMLInData: false
        },document.createElement('div'));

        // append the new grid to the div "grid":
        dojo.byId("grid").appendChild(grid1.domNode);

        // Call startup, in order to render the grid:
        grid1.startup();

});
</script> 
</head> 

<body class="claro"><div id="grid" style="width: 100%; height: 100%;"></div></body>


推荐答案

Save-API 。还有一个美丽的示例。只需适应您的store._saveCustom:

Save-API for ItemFileWriteStore. There is also a beautiful example on the bottom of the page. Just adapt your store._saveCustom:


geoStore2._saveCustom = function(saveComplete, saveFailed) {
            var changeSet = geoStore2._pending;
            var changes = {};
            changes.modified = [];
            for (var i in changeSet._modifiedItems) {
                var item = null;
                if (geoStore2._itemsByIdentity) {
                    item = geoStore2._itemsByIdentity[i];
                } else {
                    item = geoStore2._arrayOfAllItems[i];
                }

                changes.modified.push(itemToJS(geoStore2, item));
            }
            //
            // send dojo.toJson(changes.modified) - Object to the server here
            //
            saveComplete();
        };


但是JsonRestStore可能对这种工作更有用。

But a JsonRestStore might be more useful for this kind of work.

这篇关于DOJO增强的DataGrid - 更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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