Jquery jqGrid自定义onCellSelect在SaveCell之前不触发

Jquery jqGrid自定义onCellSelect在SaveCell之前不触发,jquery,jqgrid,Jquery,Jqgrid,我正在onCellSelect中编写一些代码,执行良好 onCellSelect: function (rowid, iCol, cellcontent) { if (iCol > 0) { $("#gridMain_d").jqGrid("resetSelection"); $("#gridMain_d").setSelection(rowid, true); } } 但问题是因为此代码before

我正在onCellSelect中编写一些代码,执行良好

onCellSelect: function (rowid, iCol, cellcontent) {
        if (iCol > 0) {
            $("#gridMain_d").jqGrid("resetSelection");
            $("#gridMain_d").setSelection(rowid, true);
        }
    }
但问题是因为此代码beforeSaveCell事件未触发。我知道这一点,因为只要我在savecell开始工作之前删除此代码。我尝试过使用return语句,但没有任何效果

更新
我对上面编写的代码进行了注释并添加了此代码

beforeSelectRow: function (rowid, e) {
        var $self = $(this), iCol, cm,
            $td = $(e.target).closest("tr.jqgrow>td"),
            $tr = $td.closest("tr.jqgrow"),
            p = $self.jqGrid("getGridParam");

        if ($(e.target).is("input[type=checkbox]") && $td.length > 0) {
            $self.jqGrid("setSelection", $tr.attr("id"), true, e);
        }
        else {
            $self.jqGrid('resetSelection');
            $self.jqGrid("setSelection", $tr.attr("id"), true, e);
        }
        return true;
    },
但savecell事件未触发之前仍

更新2

这个JSFIDLE复制了这个问题

有许多相互依赖的回调。此外,在不同版本的jqGrid中,这种依赖关系可能会有所不同。我建议您在选择Row之前使用
,而不是在CellSelect
上使用
,因为这将是单击jqGrid的单元格时调用的第一个回调。您可能需要的所有信息都可以从选择行之前的
的第二个参数(
e
,在下面的代码中)中获得:

beforeSelectRow: function (rowid, e) {
    var $self = $(this),
        $td = $(e.target).closest("tr.jqgrow>td");
        iCol = $.jgrid.getCellIndex($(e.target).closest($td[0]),
        colModel = $self.jqGrid("getGridParam", "colModel"),
        columnName = colModel[i].name;
    //...
    // one can use here $td.html(), $td.text() to access the content of the cell
    // columnName is the name of the column which cell was clicked
    // iCol - the index of the column which cell was clicked
    return true; // or false to suppress the selection
}
您需要记住的是,
beforeselectionrow
应该返回一个值,通知jqGrid是否选择单击的行。从SelectRow
之前的
返回的值
false
“stop”
将禁止选择单击的行。所有其他值都允许进行选择

更新:我再次分析了您的代码,希望找到了您问题的原因。您可以使用
resetSelection
,这在使用单元格编辑时是有害的。查看
resetSelection

t.p.savedRow = [];
销毁保存当前编辑单元格信息的数组。因此,无法再保存或还原单元格

要解决此问题,必须从代码中删除
resetSelection
。如果确实需要使用
resetSelection
,则应将其替换为循环调用
setSelection
。相应的代码可能与下面的代码相近:

beforeSelectRow: function (rowid, e) {
    var $self = $(this), iCol, cm, i, idsOfSelectedRows,
        $td = $(e.target).closest("tr.jqgrow>td"),
        $tr = $td.closest("tr.jqgrow"),
        p = $self.jqGrid("getGridParam");

    if ($(e.target).is("input[type=checkbox]") && $td.length > 0) {
        $self.jqGrid("setSelection", $tr.attr("id"), true, e);
    }
    else {
        //$self.jqGrid('resetSelection');
        idsOfSelectedRows = p.selarrrow.slice(0); // make copy of the array
        for (i = 0; i < idsOfSelectedRows.length; i++) {
            $self.jqGrid("setSelection", idsOfSelectedRows[i], false, e);
        }
        $self.jqGrid("setSelection", rowid, false, e);
    }
    return false;
},
在选择行之前:函数(rowid,e){
var$self=$(此)、iCol、cm、i、IDSOF选定箭头、,
$td=$(e.target).closest(“tr.jqgrow>td”),
$tr=$td.closest(“tr.jqgrow”),
p=$self.jqGrid(“getGridParam”);
if($(e.target).is(“输入[type=checkbox]”)和$td.length>0){
$self.jqGrid(“setSelection”,$tr.attr(“id”),true,e);
}
否则{
//$self.jqGrid('resetSelection');
idsOfSelectedRows=p.selarrrow.slice(0);//制作数组的副本
对于(i=0;i
@eranjali08:您能否提供一个小演示,其中包含再现问题的测试用例的描述?@eranjali08:请参阅我答案的更新部分和演示的修改版本,它就像一个符咒。太感谢你了@Oleg:)@eranjali08:不客气!如果问题解决了,你应该回答。您还有权每天投票选出30个答案或问题(请参阅)。你应该使用权利和投票权,对你阅读并发现有帮助的每一篇文章(不仅仅是你问题的答案)进行投票。它帮助其他读者找到文章,因为搜索引擎使用投票计数。你应该不做连续的投票(不要在短时间内投票给很多答案)。再次感谢:)