在OnSelectRow外部访问JqGrid选定值

时间:2011-08-11 06:49:15

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

我有一个带子网格的Jqgrid。在子网格上,我在asp.net mvc 3中应用了添加和删除功能。代码如下:

 onSelectRow: function () {
                        var myGrid = $("#" + subgrid_table_id),
                        selRowId = myGrid.jqGrid('getGridParam', 'selrow'),
                        celValue = myGrid.jqGrid('getCell', selRowId, 'PermissionID');
                        permissionID = celValue;
                    }
                });
                $("#" + subgrid_table_id).jqGrid('navGrid', '#' + subgrid_div_id,
            { add: true, del: true, edit: false, search: false },
            { width: '250', url: '@Url.Action("Update", "Role")' },
            { width: '250', url: '/Controler/Action/' + row_id },
            { width: '250', url: "/Controler/Action//" + row_id + "/" + permissionID });

permissionID全局定义为0.但是当我按下网格的删除按钮时,它不会将权限ID的新值传递给控制器​​。当我调试它成功更改permissionID时。

有谁知道这个问题是什么?

谢谢

1 个答案:

答案 0 :(得分:0)

由于Oleg的缘故,解决了一个不同的场景。代码如下:

$("#" + subgrid_table_id).jqGrid('navGrid', '#' + subgrid_div_id,
    { add: true, del: false, edit: false, search: false },
    { width: '250', url: '/Controler/Action' },
    { width: '250', url: '/Controler/Action/' + row_id })
    .navButtonAdd('#' + subgrid_div_id, {
        caption: '',
        tooltip: 'Delete row',
        buttonicon: "ui-icon-trash",
        onClickButton: function () {
            var myGrid = $("#" + subgrid_table_id);
            var selRowId = myGrid.jqGrid('getGridParam', 'selrow');
            var celValue = myGrid.jqGrid('getCell', selRowId, 'PermissionID');
            if (selRowId === null && celValue === false) {
                alert("Please select row");
                return;
            }
            $.post("/Controler/Action",{"roleid":id1,"id2":selRowId,"id3":celValue},
            function (data) {
                if (data == true) {
                    alert("Association Deleted");
                    $("#" + subgrid_table_id).trigger("reloadGrid");
                }
                else {
                    alert("An error occured");
                }
            });
        },
        position: 'last'
    });