2010-08-24 22 views
1

我正在使用ASP.MVC和jqgrid 3.7.2。數據將加載到網格和子網格中。更新表格的主要部分效果很好。我可以更新或從子網格中刪除一行,因爲子網格中的一個字段是父行的主鍵。但是,當試圖添加一行時,行被髮回服務器,我無法獲得父行的ID。所有其他子網格值都按預期發佈。我想要獲得父母的「選擇」行,但父母行沒有被選中,所以我不知道如何去獲取母表中的父行Id(主鍵),因此將是一個外鍵在細節表中。當有任何數據是子網格時,我也可以獲得父級的ID,因爲我的子網格的所有行都將其作爲隱藏字段。我注意到,在發佈後,Id字段是回發的一部分,但值爲空。有任何想法嗎?我正在使用導航欄中的編輯。jqGrid - 如何將行添加到子網格?或如何從父行獲得主鍵?

回答

1
subGridRowExpanded: function (subgrid_id, row_id) { 
    var currentRow = $('#UtilitiesGrid').jqGrid('getRowData', row_id); 
    var utilityPrimaryKey = currentRow.UtilityId; 
... 

colNames: ['parentid','subid',...], //insert parentid column, hidden 
colModel: [{name:"parentid", index:"parentid", hidden:true, editable:true, 
     editoptions: { 
      disabled:true, //dissabled in case colModel->hidden=false 
      value:utilityPrimaryKey , //Value for parentid in the add form 
     }, 
      {name:"subid",index:"subid",key:true,hidden:true} 
... 

$("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{ 
        add:true, 
        del:true, 
        refresh:true, 
        refreshstate:"current", 
        search:false, 
       }, 
       {},//edit options 
           //add options 
       {recreateForm:true //since clearAfterAdd is trueby default, recreate the form so we re-establish value for parent id 
       }); 
1

當行被展開時,我最終保存了主鍵。然後,我在添加選項使用該值的navgrid

subGridRowExpanded: function (subgrid_id, row_id) { 
    var currentRow = $('#UtilitiesGrid').jqGrid('getRowData', row_id); 
    var utilityPrimaryKey = currentRow.UtilityId`; 
    ... 

$("#" + subGridTableId).jqGrid('navGrid', "#" + pagerId, { edit: true, add: true, del: true, search: false, view: false, refresh: true }, 
    ... 
    { // Add Options 
     reloadAfterSubmit: true, 
     afterSubmit: CheckForError, 
     closeAfterAdd: true, 
     url: "/Options/AddUtilityPwsId/" + utilityPrimaryKey 
    }, 
2

我只是想出做同樣的一個很懶惰的方式: 我用:

  editurl:"datasource/notas_edit.php?pid="+row_id, 

然後我得到的值它與PHP中的$ _GET ...懶惰,但工程!