How to publish variable data using editData or onclickSubmit in jqgrid

I cannot get editData or onclickSubmit to do what I need.

I want the grid to keep track of the added or edited row after the update. Therefore, I need to post additional information so that the server can return the identifier and correct the page of the added / edited record.

I was able to do this using addfunc and editfunc and a custom form, but I would like to do this using the generated jqgrid forms.

I have a global declaration declared before the DocumentReady function. Then I tried to use editData in the editing options and set the variables to beforeSubmit or beforeInitData. Variables are sent to the server, but only as they are declared. It appears that editData is created upon initialization and cannot be updated. I also tried using onclickSubmit, but could not get this to work.

Here's an edited example:

var data2pass = {};
    data2pass['sortColumnName'] = '';
    data2pass['sortOrder'] = '';
    data2pass['rowNum'] = '';

$(document).ready(function(){

  $("#ProdGrid").jqGrid({
    url:'products_DAT.php?thespot=server_ProdGrid',
    datatype: 'json',
    mtype: 'POST',
    colNames:['ID','Product Name:','Category:','Unit Price:'],
    colModel :[ 
      {name:'ProductID', editable:true},
      {name:'ProductName', editable:true},
      {name:'CategoryID', editable:true, edittype:"select", editoptions: { dataUrl:  "products_DAT.php?thespot=select4_CategoryID" }},
      {name:'UnitPrice', align:'right', editable:true, formatter:'currency'}
    ],
    pager: '#ProdGrid_pager',
    rowNum: 15,
    sortname: 'ProductName',
    sortorder: 'asc',
    gridview: true,
    editurl: 'products_DAT.php?thespot=update_ProdGrid',
    height: 'auto'
  });

$("#ProdGrid").jqGrid('navGrid','#ProdGrid_pager', {},
{closeAfterEdit:true, reloadAfterSubmit: false, editData: data2pass,
    beforeInitData: function(formid) { 
    data2pass['sortColumnName'] = 'ProductName';
    data2pass['sortOrder'] = 'asc';
    data2pass['rowNum'] = '15';
    }
}, // Edit parameters
{}, // Add Parameters
{reloadAfterSubmit:true}, // Delete parameters
{}, // Search params
{} // View params
 );

However, the data2pass variables are first declared, which are sent to the server. What event should be used to update data2pass values ​​to send to the server? Or is there another better way to do this?

Any advice is appreciated.

thank

0
source share
2 answers

editData

editData: {
    sortColumnName: function () { return "ProductName"; },
    sortOrder: function () { return "asc"; },
    rowNum: function () { return 15; }
}

onclickSubmit ,

onclickSubmit: function (options, postData) {
    return {
        sortColumnName: "ProductName",
        sortOrder: "asc",
        rowNum: 15
    };
}

serializeEditData

serializeEditData: function (postData) {
    return $.extend(true, {}, postData, {
        sortColumnName: "ProductName",
        sortOrder: "asc",
        rowNum: 15
    });
}

. , .

+2

, , , postData, , .

$('#gridName').jqGrid('setGridParam', { postData: { KeyName: KeyValue } }).trigger('reloadGrid', [{ page: 1}]);

, ,

$(#gridName).jqGrid('editGridRow', rowid, { editData: { KeyName: KeyValue
0

All Articles