如何获取扩展的jqGrid行列数据

时间:2013-09-27 15:04:28

标签: javascript jquery asp.net asp.net-mvc jqgrid

当展开Main jqGrid行时,将构造并显示子网格。我需要在构造子网格之前捕获主网格扩展的行列数据。为此,我正在使用主网格的subGridBeforeExpand事件。在那种情况下,我正在调用一个javascript代码来捕获扩展的行列数据,但没有任何成功。 警告将sel_id抛出为空。任何人都可以指导我吗?我是否需要使用其他网格事件或我的jquery代码出错?

**<script type="text/javascript">
     function GetValues() {
       var sel_id = jQuery("#ServersWS").jqGrid('getGridParam', 'selrow'); 
       alert(sel_id);
       var rowData = jQuery("#ServersWS").jqGrid('getRowData', sel_id);
       var temp = rowData['Description']; //replace name with you column
       alert(temp);
    }
</script>**     

 div id="gridWrapper1" style="display: none">
    @{

        var grid1 = new JqGridHelper<Configuration.Models.Post.ProfileModel>(
            "ServersWS",
            caption: "Server Profiles With One or More Settings",
            hidden: false,
            hiddenEnabled: true,
            dataType: JqGridDataTypes.Json,
            methodType: JqGridMethodTypes.Post,
            pager: true,
            rowsNumber: 10,
            sortingName: "Profile",
            sortingOrder: JqGridSortingOrders.Asc,
            url: Url.Action("GetServersWithSettings"),
            **subGridBeforeExpand: "function(id) {GetValues();}",**
            subgridEnabled: true,
            subgridHelper: new JqGridHelper<PlatformConfigurationEditModel>(
                "ProfileSettingsEdit",
                caption: "Edit Settings",
                hidden: false,
                hiddenEnabled: true,
                dataType: JqGridDataTypes.Json,
                methodType: JqGridMethodTypes.Post,
                pager: true,
                rowsNumber: 10,
                sortingName: "Id",
                sortingOrder: JqGridSortingOrders.Asc,
                url: Url.Action("GetEditableProfileSettings"),
                editingUrl: Url.Action("Edit"),
                viewRecords: true,
                autoWidth: true,
                sortable: true)
                .Navigator(new JqGridNavigatorOptions { Search = false },
                    new JqGridNavigatorEditActionOptions { Url = Url.Action
                    ("Update"),CloseAfterAdd = true, CloseAfterEdit = true, Width = 500, Height  
                     = 300 },
                    new JqGridNavigatorEditActionOptions { Url = Url.Action("Add"), 
                    CloseAfterAdd = true, CloseAfterEdit = true, Width = 500, Height = 300 },
                    new JqGridNavigatorDeleteActionOptions { Url = Url.Action("Delete") },
                    null, new JqGridNavigatorViewActionOptions { LabelsWidth = "60%" }
                )
                .FilterToolbar(options: new JqGridFilterToolbarOptions
                {
                    StringResult = true,
                    DefaultSearchOperator = JqGridSearchOperators.Cn,
                    AutoSearch = true,
                    SearchOnEnter = false
                }),
                sortable: true
            ).FilterToolbar(new JqGridFilterToolbarOptions
            {
                StringResult = true,
                DefaultSearchOperator = JqGridSearchOperators.Cn,
                AutoSearch = true,
                SearchOnEnter = false,

            });
        @grid1.GetHtml()
    }
</div>

1 个答案:

答案 0 :(得分:2)

我不熟悉Lib.Web.Mvc库,但您可以尝试使用jQuery events代替callbacks。例如,jqGridSubGridBeforeExpand可能是您所需要的:

jQuery("#ServersWS").bind("jqGridSubGridBeforeExpand", function (e, pID, rowid) {
    alert("rowid=" + rowid);
});