开发者

jqGrid - how to add row to subgrid? or how to get primary key from parent row?

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 I开发者_如何学JAVAd. 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.


i just figured a very lazy way of doing the same: i used :

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

Then i get the value of it with $_GET in php ... lazy but works!


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
                });  


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜