繁体   English   中英

在jqGrid中内联编辑后如何将一行的数据保存到服务器?

[英]How to save one row's data to the server after inline editing in jqGrid?

我已经看到了@Oleg 的几乎所有示例和答案,但还没有真正找到解决方案。 这是我的网格-

 $(grid).jqGrid({
                 datatype: 'local', 
                 mtype: 'GET',
                 url: "/Views/MyUrl",
                 editUrl: "/Views/MyEditUrl",
                 colNames: colNames,
                 colModel: colModel,
                 altRows: false,
                 pager: $(pager),
                 loadonce: true,
                 sortable: true,
                 multiselect: false,
                 viewrecords: true,
                 shrinkToFit: false,                    
                 gridView: true
                // onSelectRow: editRow   
             }).navGrid(pager, { add: false, edit: false, del: false, search: false} 

             $grid.jqGrid('inlineNav', pager, {
                 edit: true,
                 add: true,
                 del: true,
                 cancel: true,
                 save: true,                    
                 editParams: {
                     keys: false
                 },
                 addParams: {
                     keys: true
                 }
             });

我正在使用jqGrid 4.6 版本和内联行编辑。
我尝试了 'onselectRow',其中我调用了 'saveRow' 而不是 'restoreRow' ,这也不起作用。
编辑该行后,我想将整行数据发送回控制器以在数据库中更新。 现在,它甚至没有命中控制器方法。

请参阅此处的链接

您必须将数据保存在函数 oneditfunc 回调上

 $(grid).jqGrid({
...
   onSelectRow: function(id){
     if(id && id!==lastSel){ 
        jQuery('#grid_id').restoreRow(lastSel); 
        lastSel=id; 
     }
     $(grid).jqGrid('editRow',rowid, 
   { 
        keys : true, 
       oneditfunc: function() {
       alert('Edit Complete');

      },
 beforeSaveRow: function (o, rowid) {
    // this is where you should save the data
    // Do validation and save the data here
    // Note, the 'beforeSaveRow' is undocumented, but it gets invoked before jqGrid calls its own SaveRow method.       
   // Get data by rowid and save it to DB and then 

    grid.saveRow(rowid, false);
    return false;// To avoid jqgrid from invoking its own save again
   },
 aftersavefunc: function (rowid) {
    // this fired is after saving
    var rowData = $this.jqGrid("getRowData", rowid);
  }
   },
...
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM