tags:

views:

61

answers:

1

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.

A: 

I ended up saving the primary key when the row was expanded. Then I used that value in the add options for the 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
     },
Rick