1

我正在使用一个JqGridsubgrid。我必须从子网格 rowId获取父 ID

请帮我解决这个问题..

我在下面粘贴我的代码。

//这是网格

$("#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
    },

//这是子网格 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

        });

    }




});
4

1 回答 1

-1

在回调函数 subGridRowExpanded 内部,您可以使用此变量,该变量已初始化为网格的 DOM(的 DOM)。所以你可以通过this.id获取父网格的id。

检查subGridRowExpanded的文档

于 2012-08-23T12:08:49.320 回答