如何让 saveRow 函数等待 jqGrid 中的 editRow 函数

How to make saveRow function wait for editRow function in jqGrid

我正在努力使 jqGrid 添加功能适应我自己的目的。我有 navButton,我想做一个特定的行为:

  1. 当用户单击该按钮时,编辑模式下的新行出现在 网格。
  2. 当用户输入数据,点击回车,数据发送至 服务器。

现在,我的代码如下所示:

 .navButtonAdd("#${pagerId}", {
                caption: "${resolveMessage('assign')}", 
                buttonicon: "ui-icon-add", 
                onClickButton: function() {
                 if (assignMode == false){
                    assignMode = true;
                    $('#${tableId}').jqGrid('addRowData', 0, {});
                    $('#${tableId}').jqGrid('editRow', 0);
                    $('#${tableId}').jqGrid('saveRow', 0, function(){ assignMode = false; }, "${assignURL}"); 
                 }
                },
                position:"last"
            })

我的问题是 saveRow 函数没有等待 editRow 结束。单击按钮后,它将立即向服务器发送空数据。如何让 saveRow 等待输入的数据?

我建议您使用 inlineNav 而不是自己重新实现相同的功能。例如,您当前的代码,例如,对每个添加的行使用相同的 rowid 0,这是非常糟糕的。此外,您在没有任何其他选项的情况下调用 editRow,然后在 editRow 之后立即调用 saveRow ,这会强制保存可能包含错误数据的空行。验证期间保存可能会失败。

此外,我建议您考虑使用 free jqGrid available for free under MIT or GNU GPLv2 licenses instead of usage commercial Guriddo jqGrid JS (see the prices here). I develop free jqGrid fork since the end of 2014 (short after the post) and have implemented really many fixes, improvements and new features described shortly in readmes to every published version, wiki articles 以及我当时发布的 steckoverflow 上的答案。