gpt4 book ai didi

jquery - 我可以更改 jqGrid 中新添加的行的 ID 吗?

转载 作者:行者123 更新时间:2023-12-01 01:17:32 27 4
gpt4 key购买 nike

我将 jqGrid 与 inlineNav 结合使用,以便用户可以在本地编辑/添加/删除行,然后在完成后将所有更改提交到服务器。我希望能够在本地向网格中添加多个新行,但由于其他要求,我需要新添加的行具有唯一的 ID,而不是默认的 new_row。另外,由于外键限制,我无法使用 ajax 调用在添加时立即保留新行。我尝试了以下操作,但 ID 值没有改变:

<input type="hidden" id="newRowIndex" />

$("#thisGrid").jqGrid('inlineNav', '#thisGridPager', {
edit: false,
addtext: "Add",
save: false,
cancel: false,
addParams: {
position: 'last',
addRowParams: {
keys: true,
oneditfunc: function (rowid) {
var newRowIndex = $("#newRowIndex").val();
if (!newRowIndex)
newRowIndex = 1;
$("#thisGrid").jqGrid('setCell', rowid, 'id', rowid + "_" + newRowIndex, '', '');
newRowIndex++;
$("#newRowIndex").val(newRowIndex);
}
}
}
});

我只想将新添加的行的 ID 设置为 new_row_1,从而增加每个新添加的行的索引。这可能吗?如果可能的话,如何实现?

解决方案

除了 Dean 的回答之外,我发现在 addRowParamsoneditfunc 中执行此操作不起作用。我发现使用jqGrid的afterInsertRow事件作品:

afterInsertRow: function (rowid, rowdata, rowelem) {
if (rowid == 'new_row') {
var newRowIndex = $("#newRowIndex").val();
if(!newRowIndex)
newRowIndex = 1;
var newRowId = rowid + "_" + newRowIndex;
$("#new_row").attr('id', newRowId);
newRowIndex++;
$("#newRowIndex").val(newRowIndex);
}
}

最佳答案

要设置新行的 ID,请使用:

 $("#new_row").attr('id',newId);

引用这个问题:Can I change the primary ID of a row in JQGrid without reloading?

关于jquery - 我可以更改 jqGrid 中新添加的行的 ID 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10835750/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com