2010-08-24 49 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 ...懒惰,但工程!