如何从子网格rowId获取父ID?

时间:2012-08-23 10:26:36

标签: jquery-plugins jqgrid subgrid

我正在使用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
    },

//这是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 个答案:

答案 0 :(得分:0)

在回调函数subGridRowExpanded中,您可以使用此变量初始化为网格的DOM(DOM的DOM)。所以你可以通过this.id得到父网格的id。

检查subGridRowExpanded

的文档