1

I am using a JqGrid and subgrid. I have to get the parent id from the subgrid rowId.

Kindly help me out in solving this..

I am pasting my code below.

//This is Grid

$("#DayEvents").jqGrid({
    url: 'Event.asmx/GetDayForEvents',
    datatype: 'json',
    mtype: 'POST',
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    serializeGridData: PrepareGridPostData,
    jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
    colNames: ['day', 'DayID'],
    colModel: [{ name: 'Day', index: 'Day', editable: false, width: 550, align: 'center', sortable: false },
    { name: 'DayID', index: 'DayID', editable: false, width: 550, align: 'center', sortable: false, hidden: true }
  ],
    rowNum: 10,
    rowList: [5, 10, 15, 20],
    // pager: "#pager2",
    viewrecords: true,
    gridview: true,
    width: '100%',
    autowidth: false,
    shrinkToFit: false,
    height: '331px',
    // pgbuttons: true,
    hoverrows: false,
    //caption: 'Days',
    subGrid: true,
    subGridUrl: 'Event.asmx/GetSubGridDay',
    subGridOptions: {
        "plusicon": "ui-icon-triangle-1-e",
        "minusicon": "ui-icon-triangle-1-s",
        "openicon": "ui-icon-arrowreturn-1-e",
        //expand all rows on load
        "expandOnLoad": false
    },

//This is Subgrid subGridRowExpanded: function(subgrid_id, row_id) {

        var subgrid_table_id, pager_id;
        subgrid_table_id = subgrid_id + "_t";
        pager_id = "p_" + subgrid_table_id;
        //alert(subgrid_table_id);
        $("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><a href=# id='AddSession' OnClick='addRow(\"" + subgrid_table_id + "\");'>add session</a><div id='" + pager_id + "' class='scroll'></div>");
        //debugger;
        jQuery("#" + subgrid_table_id).jqGrid({

            url: 'Event.asmx/GetSubGridDay',
            datatype: 'json',
            mtype: 'POST',
            cellEdit: true,
            cellsubmit: 'clientarray',
            onCellSelect: GridCellClick,               


            ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
            serializeGridData: PrepareGridPostData,
            jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
            colNames: ['session', 'start time', 'end time'],
            colModel: [

                 { name: 'SessionName', index: 'SessionName', width: 90, formatter: 'text', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]} },
                  { name: 'StartTime', index: 'StartTime', width: 90, formatter: 'number', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]} },
                 { name: 'EndTime', index: 'EndTime', width: 90, formatter: 'number', align: 'center', edittype: 'text', editable: true, editoptions: { size: 10, maxlength: 15, dataEvents: [{ type: 'change', fn: GetRemainingEffort }, { type: 'focus', fn: clearCellValues }, { type: 'blur', fn: resetCellValues}]} }

            ],

            rowNum: 10,
             height: 'auto',
            autowidth: true

        });

    }




});

1 Answers1

-1

Inside of callback function subGridRowExpanded you can use this variable which is initialized to the DOM of the grid (DOM of the ). So you can get id of the parent grid by this.id.

check for documentation of subGridRowExpanded

Piyush Sardana
  • 1,748
  • 4
  • 19
  • 33
  • @JamWaffles I have pasted my code.Please check with that and provide me a solution –  Aug 24 '12 at 04:13
  • This is so dangerous. we expand a row then expand another row after that select child row of previous row to update or delete. pureRowId will be incorrect. – Nguyễn Xuân Hoàng Jul 28 '18 at 08:05