jQgrid row is edited using inline editing mode. Pressing Enter sends data to server using http POST . POST method returns status 400 Bad reguest if there was some error. errorofunc in code below show error in this case. User corrects data in row and presses enter again.
Pressing enter is ignored, nothing happens. It looks like Enter key is unbound if 404 error is returned. Changes in edited row are lost, they cannot saved.
我试图犯错误。
restoreAfterError = false; grid.restoreAfterErorr = false;
但是,在出现错误后,行刑仍不能再拯救。
How to allow to save correct row data after 400 error is returned ?
<script type="text/javascript">
var lastSelectedRow;
$(function () {
var grid = $("#grid");
grid.jqGrid({
url: /Grid/GetData ,
datatype: "json",
mtype: POST ,
scroll: 1,
multiselect: true,
multiboxonly: true,
scrollingRows : true,
autoencode: true,
colModel: [
{ name: Source , fixed: true, editable: true, width: 30 },
{ name: Est , fixed: true, editable: true, width: 271 },
{ name: Istopic , fixed: true, editable: true, width: 57 },
{name: Critical , fixed: true, editable: true, width: 50}
],
gridview: true,
pager: #pager ,
sortname: est ,
viewrecords: true,
rowNum: 30,
sortorder: "asc",
editurl: /Grid/Edit
});
$("#grid").jqGrid( bindKeys , {
onEnter: function(rowid) {
doeditRow(rowid);
}
} );
});
function doeditRow(rowID) {
var grid2 = $("#grid");
if (rowID && rowID !== lastSelectedRow) {
grid2.jqGrid( restoreRow , lastSelectedRow);
lastSelectedRow = rowID;
}
invokeEditRow();
}
function errorfunc(rowID, response) {
// todo: why this does not allow Enter key to continue ase after error:
restoreAfterError = false;
$("#grid").restoreAfterErorr = false;
alert(response.responseText);
lastSelectedRow = rowID;
invokeEditRow();
return true;
}
function invokeEditRow() {
$("#grid").jqGrid( editRow , lastSelectedRow ,true,null, null, null, {},
null,
errorfunc
);
}
</script>
<div id="grid1container" style="width: 100%;">
<table id="grid">
</table>
<div id="pager">
</div>
</div>
UPDATE: errrofunc calls editrow which according to https://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js should set enter key again to save. For unknown reason this does not occur.
UPDATE: in errorfunc grid. is changed to
$("#grid").restoreAfterErorr = false;
according to Oleg comment