【问题标题】:How to save one row's data to the server after inline editing in jqGrid?jqGrid内联编辑后如何将一行的数据保存到服务器?
【发布时间】:2016-08-29 03:34:28
【问题描述】:

我已经看到了@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' ,但这也不起作用。
编辑行后,我想将整行数据发送回控制器以在数据库中更新。现在,它甚至没有命中控制器方法。

【问题讨论】:

  • JavaScript 区分大小写。选项editUrlgridView 将被忽略,因为jqGrid 只知道editurlgridview: true。您使用inlineNav 在导航栏中创建“保存”和“取消”按钮。如果用户单击“保存”按钮,则将调用 saveRow。如果用户单击“取消”按钮,则调用 restoreRowonSelectRow 内不需要额外的代码。
  • @Oleg,我完全忽略了 editUrl 大小写。 :( 是的,使用 inlineNav 是对的。将其更改为“editurl”,现在我可以看到它在控制器中命中了方法。

标签: javascript asp.net-mvc jqgrid


【解决方案1】:

查看链接 Here

你必须在函数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);
  }
   },
...
});

【讨论】:

    猜你喜欢
    • 2018-09-23
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多