【问题标题】:jqGrid - how to add row to subgrid? or how to get primary key from parent row?jqGrid - 如何将行添加到子网格?或者如何从父行获取主键?
【发布时间】:2010-08-24 18:41:05
【问题描述】:

我正在使用 ASP.MVC 和 jqgrid 3.7.2。数据可以正常加载到网格和子网格中。更新表格的主要部分效果很好。我可以从子网格中更新或删除一行,因为子网格中的一个字段是父行的主键。但是,当该行回发到服务器时尝试添加一行时,我无法获取父行的 ID。所有其他子网格值都按预期发布。我想过尝试获取父行的“选定”行,但未选择父行,所以我不确定如何在主表中获取父行 ID(主键),因此将是外键在明细表中。当有任何数据是子网格时,我也可以获取父级的 id,因为我的所有子网格的行都将其作为隐藏字段。我注意到在发布期间,Id 字段是回发的一部分,但值为 null。有任何想法吗?我正在使用导航栏中的编辑。

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    我只是想出了一个非常懒惰的方法来做同样的事情: 我用过:

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

    然后我在 php 中使用 $_GET 获得它的价值...懒惰但有效!

    【讨论】:

      【解决方案2】:
      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
                      });  
      

      【讨论】:

        【解决方案3】:

        当行展开时,我最终保存了主键。然后我在导航网格的添加选项中使用了该值

        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
             },
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-21
          相关资源
          最近更新 更多