[英]jqGrid - Saving an Inline Edit not working
I have a jqGrid with a list of users in it using inline add/edit functions. 我有一个jqGrid,其中使用内联添加/编辑功能在其中列出了用户列表。 For some reason, I cannot get jqGrid to save the edits I have made when my saveEdit
function is called, but the data will save if I press the enter
key. 由于某些原因,我无法让jqGrid保存我在调用saveEdit
函数时所做的编辑,但是如果按enter
键,数据将被保存。 If I comment out the inlineNav
line of jqGrid, everything works as expected. 如果我注释掉inlineNav
行,一切都会按预期进行。
To clarify, no request is ever sent to the server when my saveEdit
function is run. 为了明确saveEdit
当运行我的saveEdit
函数时,没有任何请求发送到服务器。 When I press the enter key, a request is sent to the server. 当我按Enter键时,请求将发送到服务器。 Any idea what is going on? 知道发生了什么吗?
Here is my code: 这是我的代码:
var editParams = {
afterSubmit: processResponse,
successfunc: function(response) {
var processed = processResponse(response);
if(processed[0] !== true) {
$.jgrid.info_dialog($.jgrid.errors.errcap, processed[1], $.jgrid.edit.bClose);
}
return processed[0];
},
bottominfo: 'Fields marked with an (*) are required',
keys: true
};
$.extend($.jgrid.edit, editParams);
$('#grid')
.jqGrid({
datatype: 'json',
colNames: ['User ID', 'First Name', 'Last Name', 'Email'],
colModel: [
{name: 'usr_id', jsonmap: 'usr_id', width: 75, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}},
{name: 'usr_fname', jsonmap: 'usr_fname', width: 75, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}},
{name: 'usr_lname', jsonmap: 'usr_lname', width: 75, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}},
{name: 'usr_email', jsonmap: 'usr_email', width: 125, editable: true, editrules: {required: true}, formoptions: {elmprefix: '(*) '}}
],
grouping: true,
shrinkToFit: false,
height: 200,
width: 800,
rowNum: 20,
rowList: [10, 20, 30, 40, 50, 100],
repeatitems: false,
ignoreCase: true,
jsonReader: { repeatitems: false, id: 'usr_id'},
pager: '#grid_pager',
url: 'dataurl.php',
editurl: 'editurl.php',
ondblClickRow: inlineEdit,
onSelectRow: saveEdit
})
.jqGrid('navGrid', '#users_pager', {add: false, edit: false, del: false, refresh: false, search: false})
.jqGrid('inlineNav', '#users_pager', {edit: false, save: false, cancel: false}); //If I comment out this line, everything works perfectly
var lastSel;
/* Start editing the row */
function inlineEdit(id, iRow, iCol) {
$(this).jqGrid('editRow', id, true, function() { focusRow(id, iCol, this); });
}
function focusRow(id, iCol, table) {
var ele = document.getElementById(id + '_' + table.p.colModel[iCol].name),
length = ele.value.length;
ele.focus();
if(ele.setSelectionRange) { //IE
ele.setSelectionRange(length, length);
}
else if(ele.createTextRange) {
var range = ele.createTextRange();
range.collapse(true);
range.moveEnd('character', length);
range.moveStart('character', start);
range.select();
}
}
function saveEdit(id) {
if(id && id != $(this).data('lastSel')) {
/* Save the last selected row before changing it */
$(this).jqGrid('saveRow', $(this).data('lastSel'), editParams);
$(this).data('lastSel', id);
}
$(this).data('lastSel', id);
}
Thank you in advance to anyone that helps me. 预先感谢任何对我有帮助的人。
well buddy, you are not using inlineNav anyhow, why do u want to keep it there? 好哥们,您无论如何都没有使用inlineNav,为什么您要保留它呢? second when you press enter, its not calling your saveEdit function, by default functionality is like this only. 其次,当您按Enter键时,它不会调用您的saveEdit函数,默认情况下,此功能仅与此类似。
I see you are saving your records on onSelectRow property and when press enter, after inline edit, this won't be called. 我看到您正在将记录保存在onSelectRow属性上,当按Enter键时,在进行内联编辑后,将不会调用该记录。 You can make your keys:false. 您可以将密钥设置为:false。 It will not trigger the request to server on enter key press. 按下Enter键不会触发对服务器的请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.