简体   繁体   中英

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. 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.
I tried 'onselectRow' in which i called the 'saveRow' instead of 'restoreRow' , that didn't work either.
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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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