简体   繁体   English

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

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

i have seen almost all the examples and answers by @Oleg out there, haven't really found a solution yet.我已经看到了@Oleg 的几乎所有示例和答案,但还没有真正找到解决方案。 Here is my Grid-这是我的网格-

 $(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
                 }
             });

I am using jqGrid 4.6 version, and inline row editing.我正在使用jqGrid 4.6 版本和内联行编辑。
I tried 'onselectRow' in which i called the 'saveRow' instead of 'restoreRow' , that didn't work either.我尝试了 'onselectRow',其中我调用了 'saveRow' 而不是 'restoreRow' ,这也不起作用。
After i edit the row, i would like to send the whole row data back to the controller to update in the database.编辑该行后,我想将整行数据发送回控制器以在数据库中更新。 Right now, it doesn't even hit the controller method.现在,它甚至没有命中控制器方法。

See the link in Here请参阅此处的链接

You have to save the data on the function oneditfunc callback您必须将数据保存在函数 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