【问题标题】:DOJO Enhanced DataGrid - update databaseDOJO 增强型 DataGrid - 更新数据库
【发布时间】:2011-10-11 05:32:26
【问题描述】:

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

【问题讨论】:

    标签: database datagrid dojo


    【解决方案1】:

    Save-API 用于 ItemFileWriteStore。页面底部还有一个beautiful example。只需调整您的商店。_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 可能对这种工作更有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 2012-02-23
      • 2011-10-18
      • 2012-11-03
      • 2013-01-27
      相关资源
      最近更新 更多