从按钮单击事件触发的jqgrid执行oncellselect

时间:2014-12-01 15:27:20

标签: jquery jqgrid

当发生未绑定到网格的按钮单击事件时,我希望能够从jqGrid中的行获取ID值。

换句话说,如果用户在网格上选择了一行并且还单击了与网格无关的按钮,我希望触发onCellSelect事件,其中该按钮点击事件可以向下传递ID从网格中检索(通过onCellSelect事件)。

所以,这里将是我尝试执行的代码示例,但不知道如何连接它。如果有人可以请求帮助,我将非常感激。

 $('#btnSPStop').on('click', function (e)
    {
    // Somehow, I need to fire an event here (similiar to below) where I can retrieve the selected grid row 
    onCellSelect: function (rowid, iCol, cellcontent) {
                    var grid = $('#fuelTicketsGrid');
                    var ID = grid.jqGrid('getCell', rowid, 'ID');
                    if (ID != "")
                        saveStopComments(ID);
            else
            alert("User must first have row selected in grid!");
                },

        return false;
    });

编辑#1

Oleg,在实现您的代码后,我收到以下错误消息: enter image description here

我得到一个有效的" selRowId"调试并选择网格中的第二行时(即" 2")。

我检查了JS的jqGrid和" rowid"被定义为。 我是否遗漏了我需要包含的网格定义的内容?

我在下面的行中收到错误:

ID = grid.jqGrid('getCell', rowid, 'ID');

这是整个修改过的功能:

$('#btnSPStop').on('click', function (e)
    {
        var grid = $('#StopPenalizeGrid-table'), ID,
        selRowId = grid.jqGrid('getGridParam', 'selrow');

        if (selRowId !== null)
        {
            ID = grid.jqGrid('getCell', rowid, 'ID');
            if (ID != "")
                $('#txtStopGridID').val(ID);
            else
                alert("You must have a row selected on the grid before clicking the Stop button!");
        }
        else
            alert("selRowId is equal to null for btnSPStop onClick method.");

        return false;
    });

1 个答案:

答案 0 :(得分:1)

在我看来,您不需要执行onCellSelect事件。您需要做的只是获取所选行的ID,然后获取所选行的"ID"列的内容。 On只需使用jqGrid的方法即可完成上述所有步骤。相应的代码如下所示:

$('#btnSPStop').on('click', function (e) {
    var grid = $('#fuelTicketsGrid'), ID,
        selRowId = grid.jqGrid('getGridParem', 'selrow');

    if (selRowId !== null) {
        ID = grid.jqGrid('getCell', selRowId, 'ID');
        if (ID != "") {
            saveStopComments(ID);
        } else {
            alert("some other error message");
        }
    } else {
        alert("User must first have row selected in grid!");
    }
    return false;
});
相关问题