【问题标题】:jqgrid saveRow on a row in edit mode fails when another row is going into edit mode当另一行进入编辑模式时,jqgrid saveRow 在编辑模式下的一行上失败
【发布时间】:2013-05-01 22:40:09
【问题描述】:

我正在使用 jqGrid 中的行编辑工具进行内联编辑,然后将数据保存在网格中(即,对 url 使用“clientArray”)。我正在使用“onSelectRow”函数将选择行置于编辑模式。

当通过保存按钮保存行时,此逻辑可以正常工作,但是当在第一行仍处于编辑模式时单击另一行时,为第一行调用 saveRow 函数不会保存更改,并且该行字段恢复为之前的值。

我已经尝试过使用和不使用“beforeSelectRow”功能。在这种情况下如何正确保存行更改?

逻辑如下:

var iRow;

...

beforeSelectRow: function (id, e) {
    if (id != null) {
        if (iRow != null && iRow != id) {
            SaveRow();
        }
    }
    return true;
},

onSelectRow: function (id, status, e) {
    if (id != null) {
        if (iRow != null && iRow != id) {
            SaveRow();
        }
        if (iRow == null) {
            iRow = id;
            $("#GridMain").jqGrid("editRow", id, false);
            $("#RowPanel").show();
        }
    }
}

function SaveRow() {
    // Save the current row if it was being edited
    if (iRow != null) {
        $("#GridMain").jqGrid("saveRow", iRow, { url: "clientArray" });
        $("#RowPanel").hide();
        iRow = null;
    }
}

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    你应该检查几件事:

    1. 检查 iRow 是否正确。如果调用 SaveRow 时需要保存的行仍然是可编辑的,您应该能够通过调用以下命令来获取行 ID,而无需保留全局变量: iRow = $('tr[aria-selected=true]', $("#GridMain")).attr('id'); // 你有正确的 id 吗?

    2. 如果您使用客户端排序,请检查您的列模型中是否至少有一个列设置为键。例如,如果你有一个隐藏的 Id 列,它应该这样设置: {name:'Id',索引:'Id',标签:'Id',可编辑:false,隐藏:true,key:true }

    另外,根据我在您的代码中看到的情况,您正在使用“#RowPanel”行来编辑值?如果是这样,您可能需要将编辑后的值发送回保存时的网格。否则,您在编辑和保存时不需要显示和隐藏任何内容。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多