In inline mode I add a new row, Edit new value, then click the ‘save’ button to server and local. However, when I continue to click the ‘edit’ button to edit the new row instead of editing the row it adds a new one. For example, first I add a new row : { aa,bb,cc}, then want to change it to { aaaa,bb,cc} by clicking the ‘edit’ button and editing it, but jqGrid sends an oper=add to the server, this leads to an add new row. I don’t understand why?
code as follow:
<%@ 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>
UPDATE
I use $('#'+$.jgrid.jpID(rowid).attr('id', result1.new_id) to refresh row id of the new row (idea from @oleg in question “how to update column after inline add in jqGrid”), and on the server I use oper=new && id !="new_row" to decide if it should be an edit or add a new row. It runs well, but I must add an aftersavefunc method.
The question above isn’t well understood by me. What I do is only bypass the question.
My problem is that I: add a new row then change it, jqgrid doesn’t change it, jqgrid sends an "oper=add" to server, this means the server will add a new row.
Another question is:
jQuery("#gridTable").jqGrid('inlineNav', "#gridPager", {
addParams : {
addRowParams : {
keys : true,
url : '/education2/json/editStudent1?inlinePoer=add'
}
},
editParams : {
url : '/education2/json/editStudent?inlinePoer=edit',
}
});
Unlike I expect, whenever I click add, edit or the save button in inline navigator, only the url : '/education2/json/editStudent?inlinePoer=edit' is fired. It seems url : '/education2/json/editStudent1?inlinePoer=add' cannot be fired, why? Could somebody help me?
I use firebug, and IE.
I think what you are missing is giving edit:true in following line
check this link
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#inlinenav and look at the parameters here. I’m not sure about it just try to give edit as true, if it works fine, great…else i’ll look into your code when i’ll be done with my office work.