【发布时间】:2014-12-14 04:09:55
【问题描述】:
我正在尝试将 JQgrid (4.7) 用于我们的项目。除了一次警告外,一切都按预期工作。编辑新添加的记录时,jqgrid 将新行添加到网格中。我将 reloadAfterSubmit 设置为 false,因为我将在网格上拥有大量数据,并且我不想为每次更改都重新加载网格。
<script type="text/javascript">
jQuery(document).ready(function () {
'use strict';
var list = $("#list");
var addPops = {
addCaption: "Add Record Set",
recreateForm:true,
reloadAfterSubmit:false,
closeAfterAdd:true,
width: 470,
afterSubmit : function(response, postdata) {
return [true, "", response.responseJSON.rows[0].rowId];
},
afterComplete: function(response,postdata,formId) {
var id=postdata.id;
var rowId=response.responseJSON.rows[0].id;
list.setRowData(id,{"rowId":response.responseJSON.rows[0].rowId});
list.setRowData(id,{"sharing":response.responseJSON.rows[0].sharing});
list.setRowData(id,{"comments":response.responseJSON.rows[0].comments});
//list.setCell(id,{"rowId":response.responseJSON.rows[0].rowId});
//list.setCell(id,{"sharing":response.responseJSON.rows[0].sharing});
//list.setCell(id,{"comments":response.responseJSON.rows[0].comments});
}
};
var editProps = {
editCaption: "Edit Record Set",
recreateForm:false,
reloadAfterSubmit:false,
closeAfterEdit:true,
width: 470
};
list.jqGrid({
url: "/DmsClient/ZoneEditManaged.action?_eventName=getRecordSets&searchText=",
datatype: "json",
editurl: "/DmsClient/ZoneEditManaged.action?_eventName=applyRecordSetChange",
colNames: ["Sharing", "Comments"],
editCaption: "Edit Record Set",
colModel: [
{ name: "sharing", width: 65,fixed:true, align: "left", editable:true, search:false},
{ name: "comments", width: 80, align: "left", editable:true, search:false,
editoptions: {size: "60"} }
],
pager: "#listPager",
rowNum: 10,
rowList: [10, 20, 30, 100, 500, 1000],
sortname: "origin",
sortorder: "desc",
viewrecords: true,
autoencode: true,
height: 100,
width: 700,
multiselect: false,
caption: "Record Sets",
}).navGrid('#listPager',{add:true,edit:true,del:false,search:false},editProps,addPops);
});
</script>
另外一个现象是,当编辑一个新创建的记录时,输入框是空的。数据存在于表体中,但在编辑时不会填充到编辑表单中。最终结果是单击更新时,它会在网格中创建一条新记录。
看起来我错过了一些东西,但无法弄清楚它是。感谢您对此的任何帮助。
更新: 从调试来看,看起来我没有将 id 从 _empty 更改为 real id,因此在编辑时,操作从编辑更改为添加。希望我可以使用 aftercomplete 事件来更改此 id 并修复操作。
【问题讨论】:
-
如果有人能指出一个不包括在每次操作后重新加载整个网格的 CRUD 函数的工作示例,我将不胜感激。我查看了演示,但它没有任何特定于 CRUD 的内容。