jqGrid - 从父网格获取未格式化的rowData

时间:2015-08-05 14:54:30

标签: jquery jqgrid

我使用subgrid跟随jqGrid和子网格。在subGridRowExpanded事件中,我尝试提醒父行的列值,如下所示 - 但它仅显示formatted值。

从showChildGrids函数中的选定父行获取列值的最佳jqGrid方法是什么?

    function showChildGrids(parentRowID, parentRowKey) 
    {
        alert(parentRowKey);
        var rowData = $(mainGrid).jqGrid('getRowData', parentRowKey)
        //var rowData = $(mainGrid).getRowData(parentRowID);

        alert(rowData.RoutingID);
    }

    function createRoutingGrid()
    {

            $(mainGrid).jqGrid({
                url: "invNewWORouting.aspx/GetRoutings",
                mtype: 'POST',
                datatype: "local", //json if want to load initially
                ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
                postData:
                {
                    workOrder: function () 
                    {
                        //var selectedWorkOrder = $( "select[class='workOrderDropdown']" ).val();
                        //return selectedWorkOrder;
                        return "5454430506";
                    }
                },

                serializeGridData: jqGridCustomSerializer,
                jsonReader: {
                    repeatitems: false,
                    root: function (obj) { return obj.d; }
                },
                colNames: ['Routing ID', 'Destinations'],
                colModel: [
                    { name: 'RoutingID', index: 'RoutingID', formatter:mySpacePreserveFormatter, width:150 },
                    { name: 'Destinations', index: 'Destinations', width:400 }
                ],
                multiselect:true,
                multiboxonly:false,
                rowNum: 10,
                viewrecords: true,
                gridview: true,
                height: "auto",
                loadonce: true,
                subGrid: true, // set the subGrid property to true to show expand buttons for each row
                subGridRowExpanded: showChildGrids, // javascript function that will take care of showing the child grid
                subGridOptions: { "plusicon" : "ui-icon-plus",
                                  "minusicon" :"ui-icon-minus",
                                  "openicon" : "",
                                  "reloadOnExpand" : false,
                                  "selectOnExpand" : false },
                beforeSelectRow: function (rowid, e) 
                {
                    //Reset all checkboxes before selection
                    $(this).jqGrid('resetSelection');

                    var $self = $(this);
                    var $td = $(e.target).closest("tr.jqgrow>td");
                    var rowid = $td.parent().attr("id");
                    var rowData = $self.jqGrid("getLocalRow", rowid);

                    //Set variable for RoutingID
                    userSelectedRoutingID = rowData.RoutingID;

                    //Allow row selection
                    return true; 
                }
            });

            //Hide header checkbox
            $("#cb_"+mainGrid[0].id).hide();
        }

格式化

        function mySpacePreserveFormatter (cellvalue, options, rowObject)
        {
         return '<pre>' + cellvalue + '</pre>';
        }

输出

enter image description here

0 个答案:

没有答案