Jqgrid 为什么内联编辑要添加新行?
在内联模式下,我添加一个新行,编辑新值,然后单击“保存”按钮,将其保存到服务器和本地。但是,当我继续单击“编辑”按钮编辑新行而不是编辑行时,它会添加一个新行。例如,首先我添加了一个新行:Jqgrid 为什么内联编辑要添加新行?,jqgrid,Jqgrid,在内联模式下,我添加一个新行,编辑新值,然后单击“保存”按钮,将其保存到服务器和本地。但是,当我继续单击“编辑”按钮编辑新行而不是编辑行时,它会添加一个新行。例如,首先我添加了一个新行:{aa,bb,cc},然后想通过单击“编辑”按钮并对其进行编辑将其更改为{aaaa,bb,cc},但jqGrid向服务器发送了一个oper=add,这将导致添加新行。我不明白为什么 代码如下: <%@ page language="java" import="java.util.*" pageEncodin
{aa,bb,cc}
,然后想通过单击“编辑”按钮并对其进行编辑将其更改为{aaaa,bb,cc}
,但jqGrid向服务器发送了一个oper=add
,这将导致添加新行。我不明白为什么
代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ddddd</title>
<link
href="/education2/jqGrid4.4/themes/redmond/jquery-ui-1.8.2.custom.css"
rel="Stylesheet" />
<link href="/education2/jqGrid4.4/themes/ui.jqgrid.css" rel="Stylesheet" />
<script src="/education2/jqGrid4.4/js/jquery-1.7.2.js"
type="text/javascript"></script>
<script type="text/javascript"
src="/education2/jqGrid4.4/js/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript"
src="/education2/jqGrid4.4/js/i18n/grid.locale-cn.js"></script>
<script src="/education2/jqGrid4.4/js/jquery.jqGrid.src.js"
type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#gridTable").jqGrid({
url : '/education2/json/searchStudent',
mtype : "POST",
datatype : "json",
colNames : [ 'studentId','studentNo', 'name', 'class'],
colModel : [ {
name : 'studentId',
index : 'studentId',
width : 55,
hidden : true,
hidedlg : true
key : true,
editable : true
}, {
name : 'studentNo',
index : 'studentNo',
width : 150,
editable : true
}, {
name : 'studentName',
index : 'studentName',
width : 150,
align : "right",
editable : true
}, {
name : 'className',
index : 'className',
width : 150,
align : "right",
editable : true,
edittype : 'select',
editoptions : {
dataUrl : "/education2/json/classNameStudent"
}
}],
jsonReader : {
root : "gridModel",
records : "record",
repeatitems : false
},
prmNames : {
search : "search",
id : "id"
},
rowNum : 10,
rowList : [ 10, 20, 30 ],
height : 400,
// multiselect : true,
// multiboxonly : true,
pager : jQuery('#gridPager'),
sortname : 'studentId',
viewrecords : true,
altRows : true,
sortorder : "desc",
editurl : "/education2/json/editStudent",
caption : "student"
});
jQuery("#gridTable").jqGrid('navGrid', "#gridPager", {
edit : false,
add : false,
del : true
}, {}, {}, {}, {
caption : "find",
Find : "find",
closeAfterSearch : true
});
jQuery("#gridTable").jqGrid('inlineNav', "#gridPager", {
editParams : {
successfunc : succesfunc1,
restoreAfterError : false
}
});
});
var succesfunc1 = function(response) {
var result = eval('(' + response.responseText + ')');
if (result.success == true) {
alert("success!");
return true;
} else {
alert(result.message);
return false;
}
};
};
</script>
</head>
<body>
<table id="gridTable"></table>
<div id="gridPager"></div>
<br />
</body>
</html>
与我预期的不同,每当我在内联导航器中单击“添加”、“编辑”或“保存”按钮时,只有url:'/education2/json/editStudent?inlinePoer=edit'
被触发。似乎url:”/education2/json/editStudent1?inlinePoer=add“
无法激发,为什么?谁能帮帮我吗
我使用firebug和IE。我认为您缺少的是在下面的行中给出edit:true
jQuery("#gridTable").jqGrid('inlineNav', "#gridPager", {
editParams : {
successfunc : succesfunc1,
restoreAfterError : false
}
});
检查此链接
看看这里的参数。我不确定,只要试着将edit设置为true,如果它工作得很好,很好……否则我会在完成办公室工作时查看您的代码。您是否正在编辑作为行键(StudentId)的列?是的,我编辑数据并将其保存到服务器,因此如果您编辑了键,您将创建一个新记录。如果您不在网格列上声明键,它将使用自动生成的行号作为键,这可能会解决您的问题。谢谢您的帮助。studentId是自动生成的行号,studentId设置为在jqgrid中键入。jqgrid无法从服务器获取新的studentId(我不知道应该从服务器返回什么),所以在我保存新行后,新行的行id设置为“new_row”,而不是从服务器以{“className”:“dfd”,“id”:“55”,“message”:“success!”,“new_id”:55,“studentId”:55,“studentName”:“fefef”,“studentNo”:“fefe”的形式返回jqgrid,“success”:true}我的问题是:添加新行然后更改它,jqgrid不更改它,jqgrid发送一个“oper=add”“对于服务器,这意味着服务器将添加新行。所以我认为jqgrid无法从服务器获得正确的返回值,所以无法设置新行的行id。我错了吗?谢谢你的帮助,但是添加编辑:true是无用的。我发现添加行的id是“new_row”,但我认为它将是studentId的int值,来自服务器的数据是{“id”:“28”,“message”:“success!”,“new_id”:28,“success”:true},也许这个返回值不是jqgrid的标准返回?谁能帮帮我吗?非常感谢。我可以向你们保证,jqgrid的row id和student id永远不会相同。jqgrid网站只提供应该发送到服务器的内容,但我无法确定应该从服务器返回哪些数据。我在哪里可以找到关于jqgrid应该从服务器返回哪些数据的文档?非常感谢。我可以更改jqgrid行的行id吗?i;我肯定你的问题没那么难,但你到底想做什么,我不明白。
jQuery("#gridTable").jqGrid('inlineNav', "#gridPager", {
editParams : {
successfunc : succesfunc1,
restoreAfterError : false
}
});