DOJO增强型DataGrid - 更新数据库

时间:2011-07-22 17:01:07

标签: database datagrid dojo

有没有人有一个工作示例,说明如何使用DOJO Enhanced DataGrid中的已编辑信息更新数据库表?我有一个postgresql数据库后端使用dojo.data.ItemFileWriteStore,它在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>

1 个答案:

答案 0 :(得分:1)

ItemFileWriteStore的

Save-API。页面底部还有一个beautiful example。只需调整你的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可能对这类工作更有用。

相关问题