2015-11-01 39 views
0

我需要我的ro基於兩個ID,即Userid和certID。當添加和更新它工作正常,但刪除時,我需要這兩個ID來刪除我的記錄在數據庫中,但所有來自POST數據是「id」和「oper」,我需要添加額外certId到發佈數據。這裏是我的代碼:jqGrid刪除行時的額外POST數據

<!DOCTYPE HTML> 
<html> 
<head> 
<title>jQGrid PHP inline Editing Tutorial</title> 
    <link type="text/css" rel="stylesheet" href="plugins/jquery-ui/jquery-ui.min.css"> 
<!--<link rel='stylesheet' href='plugins/jqGrid/css/ui.jqgrid.css'/>--> 
    <link type="text/css" rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" media="screen" href="plugins/jqGrid/css/ui.jqgrid-bootstrap.css" /> 

    <script type="text/ecmascript" src="plugins/jquery/jquery-2.1.0.min.js"></script> 
    <script type="text/ecmascript" src='plugins/jqGrid/js/i18n/grid.locale-en.js'></script> 
    <script type="text/ecmascript" src='plugins/jqGrid/js/jquery.jqGrid.min.js'></script> 
    <script type="text/ecmascript" src="plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script> 
    <script type="text/ecmascript" src="plugins/bootstrap-typehead/js/bootstrap3-typeahead.min.js"></script> 
    <link rel="stylesheet" type="text/css" media="screen" href="plugins/bootstrap-datepicker/css/bootstrap-datepicker.css" /> 
<meta charset="utf-8" /> 

<script> 
    $.jgrid.defaults.width = 780; 
    $.jgrid.defaults.responsive = true; 
    $.jgrid.defaults.styleUI = 'Bootstrap'; 
</script> 
</head> 
<body> 
<div style="margin-left:20px;"> 
    <table id="jqGrid"></table> 
    <div id="jqGridPager"></div> 
</div> 
    <script type="text/javascript"> 

$(document).ready(function() { 

    $("#jqGrid").jqGrid({ 
     url: 'getUserCertList.php', 
     editurl: 'UserCertUpdate.php', 
     mtype: "GET", 
     datatype: "json", 
     page: 1, 
     colModel: [ 
         { label: 'userID', name: 'id', editable: false, editrules: { edithidden: true }, hidden: true, width: 40, align: 'left' }, 
         { label: 'certificationid', name: 'certificationid', key: true, editable: false, editrules: { edithidden: true }, hidden: true, width: 40, align: 'left' }, 
         { 
          label: 'Certification', 
          name: 'certid', 
          width: 200, 
          editable: true, 
          edittype: "select", 
          editrules : { required: true}, 
          editoptions : {dataUrl: "getCertList.php"} 
         }, 
         { 
          label  : 'Date Certified', 
          name  : 'dateCertified', 
          width  : 80, 
          align  : 'center', 
          editable : true, 
          sortable : true, 
          sorttype : 'date', 
          edittype : "text", 
          editrules : { required: true}, 
          editoptions : { 
          // dataInit is the client-side event that fires upon initializing the toolbar search field for a column 
           // use it to place a third party control to customize the toolbar 
           dataInit: function (element) { 
            $(element).datepicker({ 
             autoclose: true, 
             format: 'yyyy-mm-dd', 
             orientation : 'auto bottom' 
            }); 
           } 
          } 
         }, 
         { 
          label  : 'Verified', 
          name  : 'verified', 
          width  : 40, 
          align  : 'center', 
          sorttype : "number", 
          editable : false, 
          edittype : "checkbox", 
          editoptions : { value: "True:False" }, 
          formatter : "checkbox", formatoptions: { disabled: true } 
         }, 
        ], 
     loadonce : true, 
     //onSelectRow: editRow, // the javascript function to call on row click. will ues to to put the row in edit mode 
     viewrecords: true, 
     height: 300, 
     rowNum: 20, 
     rownumbers: true, // show row numbers 
     rownumWidth: 35, // the width of the row numbers columns 
     pager: "#jqGridPager" 
    }); 

     $('#jqGrid').navGrid("#jqGridPager", {edit: false, add: false, del: true, refresh: true, view: true, search:false}, 
          {delData: { 
           name: function() { 
             var cert_id = $('#jqGrid').jqGrid('getGridParam', 'selrow'); 
             var value = $('#jqGrid').jqGrid('getCell', cert_id, 'colName'); 
             return value; 
           } 
          } 
        }); 
     $('#jqGrid').inlineNav('#jqGridPager',{edit: false,add: true,del: true,cancel: true, 
           editParams: {keys: true,}, 
           addParams: {keys: true}, 
          }); 


}); 

    </script> 

</body> 
</html> 
+0

你作爲從'getUserCertList.php'返回的數據'id'用什麼(填充網格中)? 'certid'列使用'key:true'屬性。因此,我可以假設'certid' anong玷污了服務器端的已刪除項目。你能得到'userID'有'certid'嗎? – Oleg

回答

2

網格有兩個隱藏列:'id'label: 'userID')和'certificationid'和使用key: true'certificationid'列。

如果我正確理解你的問題,那麼來自兩個值userIDcertificationid的組合指定需要刪除的項目。在這種情況下,最好更改從服務器返回的數據,並使用userID + "_" + certificationid作爲服務器響應中id屬性的值。順便說一下,網格不需要隱藏'id'列。 id值將用於分配行的id屬性的值(<tr>元素)。因此,不需要在隱藏列的<td>中保存相同的信息。

我你不能在服務器端進行建議的更改,那麼你可以使用onclickSubmit回調來擴展數據。你所造成的代碼中使用delData的編輯形式的選項,這是不對的內部:

$('#jqGrid').navGrid("#jqGridPager", 
    {edit: false, add: false, del: true, view: true, search: false}, 
    {}, // edit parameters 
    {}, // add parameters 
    { // del parameters 
     onclickSubmit: function (options, delId) { 
      // get the vale from 'id' (label: 'userID') column 
      // and extend the postdata with name property 
      return { 
       name: $(this).jqGrid('getCell', delId, 'id') 
      }; 
     } 
    } 
); 
+0

哇,這很快,謝謝你是最好的。我將在代碼中進行更改以刪除id的隱藏值。 – boulepick

+0

@boulepick:不客氣! – Oleg