dojox.grid.enchancegrid可编辑字段强制保存

时间:2012-10-12 08:14:40

标签: javascript datagrid dojo

我有一个增强网格,哪些字段是可编辑的。某些字段将手动更改,而其他字段将动态更改。问题是我不想将值存储在ApplyEdit上,我想强制保存值但我无法找到它的解决方案。以下是现在实际上工作得很好的方法。

dojo.connect(grid, "onApplyEdit", grid, function(evt, rowIndx, fieldIndx){
            var selected_item = grid.getItem(evt);
            //Not sure if this is the most efficient way but it worked for me
            var row_id = grid.store.getValue(selected_item, "row_id");
            var from_item_no = grid.store.getValue(selected_item, "from_item_no");
            var from_inventory = grid.store.getValue(selected_item, "from_inventory");
            var comment = grid.store.getValue(selected_item, "comment");
            edit_quantity = grid.store.getValue(selected_item, "quantity");
            var to_item_no = grid.store.getValue(selected_item, "to_item_no");
            var to_inventory = grid.store.getValue(selected_item, "to_inventory");
            var foundation = grid.store.getValue(selected_item, "foundation");

                // Instantiate some write implementing store.
                var store = grid.store;
                // Set our load completed handler up...
                var onCompleteFetch = function(items, request){
                    // Define the save callbacks to use
                    var onSave = function(){
                        dojo.xhrPost({
                            url: url,
                            content: {
                                row_id: row_id,
                                from_item_no: from_item_no,
                                from_inventory: from_inventory,
                                comment: comment,
                                quantity: edit_quantity,
                                to_item_no: to_item_no,
                                to_inventory: to_inventory,
                                foundation: foundation
                            },
                            handleAs: "text",
                            load: function(data){
                                console.log("Returned value: " + data);
                                global_saved_check = false;
                            },
                            error: function(error){
                                alert(error);
                            }
                        });// end xhrPost
                    } // end onSave

                    var onSaveError = function(error){
                            alert("Error occurred: " + error);
                    }

                    // If the store has modified items (it should), call save with the handlers above.
                    if(store.isDirty()){
                            store.save({onComplete: onSave, onError: onSaveError});
                    }
                } // end onCompleteFetch
                // Define a fetch error handler, just in case.
                var onFetchError = function(error, request){
                        alert("Fetch failed.  " + error);
                }
                // Fetch some data...  All items with a foo attribute, any value.
                store.fetch({query: {foo:"*"}, onComplete: onCompleteFetch});

        });//end connect onApplyEdit

0 个答案:

没有答案