Reputation: 175
I am using the jqGrid 4.13.3 - free.
I need to use the errofunc callback of the editRow but I get a JavaScript error when accessing the form(page) saying expected ")". In the code I have comments explain what works and then changes made that cause the error.
function oSelect(id, status, e) {
selID = id;
rejflag = $("#kcdimensionlist").getRowData(id)['rejectedi'];
$("#kcdimensionlistV7").setColProp('rejectedi', {
editoptions: {
dataUrl: '/QMSWebApp/GenericControllerServlet?lifecycle=twowayoptionlist'
},
defaultValue: 0
});
$("#kcdimensionlistV7").setColProp('rechecki', {
editoptions: {
dataUrl: '/QMSWebApp/GenericControllerServlet?lifecycle=threewayoptionlist_NA'
},
defaultValue: 0
});
var target = $(e.target);
if (!target.is("img")) {
if (id && id !== lastsel) {
$("#kcdimensionlistV7").jqGrid('restoreRow', lastsel);
//This line works fine but when commented out and modified to next line it fails
//$("#kcdimensionlistV7").jqGrid('editRow',id,true);
$("#kcdimensionlistV7").jqGrid('editRow', id, true, errorfunc: eFunc);
lastsel = id;
}
}
};
This is my eFunc
function:
function eFunc(response, rowid) {
var res = $.parseJSON(response.responseText);
if (res) {
if (!res.errorCode) {
return [false, res.errorMsg];
} else {
return [true];
}
}
}
Update to code:
function oSelect(id, status, e) {
selID = id;
rejflag = $("#kcdimensionlist").getRowData(id)['rejectedi'];
$("#kcdimensionlistV7").setColProp('rejectedi', {
editoptions: {
dataUrl: '/QMSWebApp/GenericControllerServlet?lifecycle=twowayoptionlist'
},
defaultValue: 0
});
$("#kcdimensionlistV7").setColProp('rechecki', {
editoptions: {
dataUrl: '/QMSWebApp/GenericControllerServlet?lifecycle=threewayoptionlist_NA'
},
defaultValue: 0
});
var target = $(e.target);
if (!target.is("img")) {
if (id && id !== lastsel) {
$("#kcdimensionlistV7").jqGrid('restoreRow', lastsel);
$("#kcdimensionlistV7").jqGrid('editRow', id, {
keys: true,
errorfunc: eFunc
});
lastsel = id;
}
}
};
function eFunc(response, rowid) {
alert("Here");
var res = $.parseJSON(response.responseText);
if (res) {
alert(res.errorCode);
if (!res.errorCode) {
return [false, res.errorMsg];
} else {
return [true];
}
}
}
This is my servlet code for testing:
else if (lifecycle.equals("editdimensiondatamodelV7")) {
boolean status = false;
String returnMsg = "This is a test";
if (request.getParameter("oper").equals("edit")) {
}
jReturnString = "{\"errorCode\": " + status + ", \"errorMsg\": \"" + returnMsg + "\"}";
response.getWriter().write(jReturnString);
}
Update:
errorfunc code:
function eFunc(res, rowid) {
var errorText = $.parseJSON(res.responseText).Message;
alert("Here: " + errorText);
return [false];
}
Servlet code Note comment:
else if (lifecycle.equals("editdimensiondatamodelV7")) {
//Would like to send a dynamic message back - Example: Dimensions are ouside of tolerance
if (request.getParameter("oper").equals("edit")) {
response.setStatus(500);
}
}
The eFunc never returns the alert and a Sending... dialog appears on grid.
Upvotes: 0
Views: 76
Reputation: 221997
You should fix the line, which contains syntax error
$("#kcdimensionlistV7").jqGrid('editRow',id,true, errorfunc: eFunc);
to
$("#kcdimensionlistV7").jqGrid('editRow', id, {
keys: true,
errorfunc: eFunc
});
I'd recommend you to upgrade old jqGrid 4.13.3 to the current free jqGrid version: 4.15.2.
Upvotes: 1