jqGrid:如果已编辑主键列,如何更新行ID [英] jqGrid: how to update row id if primary key columns was edited
问题描述
主键值用作从服务器返回的json数据中的行ID. 如果主键值被编辑并保存了两次,则第二次保存会导致错误,因为jqGrid 再次将原始主键值传递给编辑方法.
Primary key values are used as row ids in json data returned from server. If primary key value is edited and saved two times, second save causes error since jqGrid passes original primary key value again to edit method.
如果在嵌入式编辑中更改了主键值,如何将jqGrid行ID更新为新的主键值?
How to update jqGrid row id to new primary key value if primary key value is changed in inline editing ?
$(function () {
var grid = $("#grid");
grid.jqGrid({
url: '<%= ResolveUrl("~/Grid/GetData?_entity=Strings")%>',
datatype: "json",
mtype: 'POST',
scroll: 1,
autoencode: true,
colModel: [{
name: 'Source',
fixed: true,
editable: true,
width: 30
}, { /* this is primary key passed also as id */
name: 'Est',
fixed: true,
editable: true,
width: 271
}, {
name: 'Eng',
fixed: true,
editable: true,
width: 167
}],
gridview: true,
pager: '#pager',
viewrecords: true,
editurl: '<%= ResolveUrl("~/Grid/Edit?_entity=Strings")%>',
...
推荐答案
rowid只是网格的相应<tr>
元素的id
属性值.因此,要将rowid oldRowid
更改为newRowid
,您应该执行以下操作:
The rowid is nothing more as the value of id
attribute of the corresponding <tr>
element of the grid. So to change the rowid oldRowid
to newRowid
you should do something like the following:
$("#" + oldRowid).attr("id", newRowid);
这篇关于jqGrid:如果已编辑主键列,如何更新行ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!