问题描述
jQgrid 行使用内联编辑模式进行编辑.按 Enter 使用 http POST 将数据发送到服务器.如果出现错误,POST 方法返回状态 400 Bad reguest.下面代码中的 errorofunc 在此显示错误案件.用户在行中更正数据并再次按回车键.
按下回车键被忽略,没有任何反应.如果返回 404 错误,看起来 Enter 键未绑定.已编辑行中的更改已丢失,无法保存.
我尝试在errorfunc中设置
restoreAfterError = false;grid.restoreAfterErorr = false;
但出错后仍无法再次保存行.
400错误返回后如何保存正确的行数据?
<script type="text/javascript">var lastSelectedRow;$(函数(){var grid = $("#grid");grid.jqGrid({url: '/Grid/GetData',数据类型:json",mtype: 'POST',滚动:1,多选:真,multiboxonly:真,滚动行:真,自动编码:真,col型号:[{名称:'来源',固定:真,可真,宽度:30 },{名称:'Est',固定:真,可真,宽度:271 },{名称:'Istopic',固定:真,可真,宽度:57 },{name:'Critical',固定:true,可true,宽度:50}],网格视图:是的,寻呼机:'#pager',排序名称:'est',观看记录:真实,行数:30,排序顺序:asc",editurl: '/网格/编辑'});$("#grid").jqGrid('bindKeys', {onEnter:函数(rowid){doeditRow(rowid);}});});函数doeditRow(rowID){var grid2 = $("#grid");if (rowID && rowID !== lastSelectedRow) {grid2.jqGrid('restoreRow', lastSelectedRow);lastSelectedRow = rowID;}调用编辑行();}函数错误函数(行ID,响应){//todo: 为什么这不允许 Enter 键在错误后继续:恢复后错误 = 假;$("#grid").restoreAfterErorr = false;警报(response.responseText);lastSelectedRow = rowID;调用编辑行();返回真;}函数调用编辑行(){$("#grid").jqGrid('editRow', lastSelectedRow ,true,null, null, null, {},空值,错误函数);}</脚本><div id="grid1container" style="width: 100%;"><table id="网格"></表><div id="寻呼机"></div></div>
更新:errrofunc 调用 editrow 哪个根据https://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js应再次设置回车键保存.由于未知原因,这不发生.
更新:在 errorfunc 网格中.改为
$("#grid").restoreAfterErorr = false;
根据奥列格的评论
你在 errorfunc
实现中使用变量 grid
(grid.restoreAfterErorr
).网格
是 undefined
并且您在该行中有异常.
已更新:您应该将 alert(response.responseText);
替换为
$.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+response.responseText +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
查看与标准情况下相同样式的对话框.内联编辑中的 errorfunc
负责显示错误消息本身.
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 thiscase.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.
I tried to set in errorfunc
restoreAfterError = false;grid.restoreAfterErorr = false;
but row still cannot saved again after error.
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: in errorfunc grid. is changed to
$("#grid").restoreAfterErorr = false;
according to Oleg comment
You use variable grid
inside of errorfunc
implementation (grid.restoreAfterErorr
). The grid
is undefined
and you have exception in the line.
UPDATED: ou should replace alert(response.responseText);
to
$.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+
response.responseText +'</div>', $.jgrid.edit.bClose,{buttonalign:'right'});
to see the same styled dialog box as in the standard case. The errorfunc
from the inline editing is responsible to display the error message itself.
这篇关于jqGrid内联编辑:如果帖子返回错误如何再次保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!