jqGrid-如何将行添加到子网格?或如何从父行获取主键? [英] jqGrid - how to add row to subgrid? or how to get primary key from parent row?
问题描述
我正在使用ASP.MVC和jqgrid 3.7.2.数据将OK加载到网格和子网格中.更新表的主要部分效果很好.我可以从子网格中更新或删除行,因为子网格中的字段之一是父行的主键.但是,当尝试将行回发到服务器时添加行时,我很难获取父行的ID.所有其他子网格值均按预期发布.我考虑过尝试获取父级的选定"行,但未选择父级行,因此我不确定如何去获取主表中的父行ID(主键),因此将成为外键在明细表中.当子网格有任何数据时,我也可以获得父级的ID,因为我的所有子网格的行都将其作为隐藏字段.我注意到在发布过程中,Id字段是回发的一部分,但该值为null.有任何想法吗?我正在使用导航栏中的编辑.
I am using ASP.MVC and jqgrid 3.7.2. The data loads OK into the grid and subgrid. Updating the master part of the table works great. I can update or remove a row from the subgrid since one of the fields in the subgrid is the primary key of the parent row. But when trying to add a row when the row is posted back to the server I am having trouble getting the parent row's Id. All the other subgrid values are posted as expected. I thought about trying to get the "selected" row of the parent, but the parent row is not selected, so I am not sure how to go about getting the parent rows Id (primary key) in master table thus will be a foreign key in the detail table. When there is any data is the subgrid, I can also get the parent's id since all my subgrid's rows have that as a hidden field. I noticed that during the post an Id field is part of the postback, but the value is null. Any ideas? I am using editing from the navigation bar.
推荐答案
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
});
这篇关于jqGrid-如何将行添加到子网格?或如何从父行获取主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!