开发者

DOJO Enhanced DataGrid - update database

Does anyone have a working example of how to update a database table with edited information from DOJO Enhanced DataGr开发者_开发知识库id? 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 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();
        };

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜