【发布时间】:2013-11-27 16:10:46
【问题描述】:
我正在创建一个 jqgrid,它由来自 jsp 的数据填充。它有 3 列名称、描述和不可编辑的列 ID。我有 5 个按钮:页面上的新建、修改、删除、确定和取消。我想让用户通过弹出表单在本地编辑/添加数据到 jqgrid,然后单击保存将其添加到数据库。
$("#template-list").jqGrid
({
url:'getTemplateCategories.jsp?TrUserId=122',
datatype: 'xml',
mtype: 'post',
colNames:['Name','Description','id','SaveAs'],
colModel :[
{name:'Name',index:'Name', width:300, align:'left', sortable:false,xmlmap:"catName", editable:true},
{name:'Description',index:'Description', width:300, align:'left', sortable:false,xmlmap:"catDescription", editable:true},
{name:'id',index:'id', width:0, align:'left', sortable:false,xmlmap:"catId" , hidden: false},
{name:'SaveAs', index:'SaveAs', width:0, align:'left', sortable:false, hidden: false}
],
xmlReader: {
root:"Categories",
row:"item",
repeatitems:false
},
height : '461',
scrollOffset:"0",
hidegrid: "No",
closeAfterAdd : true,
closeAfterEdit : true,
border: '2',
pager: '#template-pager',
viewrecords: true,
minheight: '190',
width: '600',
autoheight: true,
mtype:'POST',
forceFit : true,
align:'left',
emptyrecords: "Nothing to display",
rowNum:'20',
paging: true,
editurl: 'TemplateCategoryWebView.jsp',
cellsubmit:'clientArray',
loadonce : true
});
我正在使用以下代码在行选择后单击按钮添加/编辑一行:
function add()
{
$("#template-list").jqGrid('editGridRow',"new",{width:400,height:200,reloadAfterSubmit:false,closeAfterAdd:true});
}
function modify()
{
var selRowId = $('#template-list').jqGrid('getGridParam','selrow');
var rowid = $('#template-list').jqGrid('getCell', selRowId, 'id') ;
var rowData = $("#template-list").jqGrid('getRowData',rowid);
if( selRowId)
{
$('#template-list').jqGrid('editGridRow',selRowId,{width:400,height:200,reloadAfterSubmit:false,closeAfterEdit:true});
alert("selRowId : "+selRowId+" rowid : "+rowid);
EditCats=EditCats.concat(rowid) ;
}
else
{
alert("Please select a row");
}
}
现在,当我编辑特定行时,它会打开该记录并允许用户编辑名称和描述值,当我单击提交按钮时,它不仅会在 jqgrid 本地保存编辑的值,还会更改“id”列值为“selRowId”的值。有人可以解释发生了什么,因为我正在努力解决这个问题。我希望此功能的行为与我提到的完全一样,而不是通过任何其他替代方法(如内联编辑),因为这是一个迁移项目,他们希望保留该功能之前的工作方式(即使用弹出屏幕)以减少客户学习曲线。很长一段时间以来,我一直在寻找解决此问题的方法,但一直没有找到。
它还尝试在 editGridRow 中传递 id 值,但它没有用。请帮忙。
谢谢, 安妮塔
【问题讨论】:
-
您能否将
colModel(name:'id',index:'id') 中的id更改为其他名称并重复相同的测试?例如,您可以使用name:'catId'代替name:'id',index:'id'。问题是名称id将在编辑数据期间在内部使用。 -
@Oleg 感谢您的回复。更改了 colModel 值,现在它可以正常进行编辑,但现在添加新行时,id 应该是 jqg1 时是空白的。
-
您至少应该使用
reloadAfterSubmit: true选项添加表单。如果您不使用它,则必须在editurl: 'TemplateCategoryWebView.jsp'的服务器响应中返回id(catId) 的新值。如果响应将是不包含在 XML 中,那么 jaGrid 将为您修改 rowid。如果您想向用户显示 id(在catId列中)或者服务器响应不是新的 id(例如 XML 包装),那么您必须使用表单编辑的afterSubmit回调。所以我的建议是:使用reloadAfterSubmit: true添加至少用于乞讨。 -
@oleg 很抱歉回复晚了,但也没有用
-
@Anita,我能就这个问题问你一些问题吗...如果这个问题解决了吗??