I am having a bit of a problem with this fantastic jqgrid plugin and my attempt to use it with WCF Data Services (not really, but the very similar odata4j services). By the way, if anyone is thinking about using jqgrid with odata services, please send me a line, I found answers to difficult questions like, for example, how to configure the grid xmlreader to read an odata xml structure defeating the jquery namespace search issue ( hints:
include jquery.xmlns.js
.....
$.xmlns.m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
$.xmlns.d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
.....
var feedXmlReaderOptions = {
root: "feed",
row: "entry",
repeatitems: false,
id: "feed>entry>id"
};
....
colModel: [
{
name: "clmNumKey",
index: "clmNumKey",
width: 150,
xmlmap: "d|clmNum",
editable: true
}
....
)
Anyway, the issue is that odata services need the method that addresses the edit operation (DELETE, PUT, MERGE) to be sent as a custom request header on a normal POST, rather than it being an http method. The reason for that seems to be that most firewalls do not allow PUT and DELETE http methods to pass, because that is how you can, for example, place new files on the server, as well as delete files, in case you can guess the valid path.
Long story short...the loadBeforeSend event is not triggered for inline or form edit...I can see it being triggered on a full data request of the grid, but I only get the serializeEditData
event triggered when I submit from the edit form.
I am worried because I went into the jqgrid source files (grid.formedit.js
, grid.inlineedit.js
) and I couldn't get any hits with the beforesend keywords, only serializeeditdata is showing there.
Am I missing something?
Is there another way to set the headers I need on the xhr
ajax object the grid uses? Is that xhr
object exposed by the grid?
Below you have the code I have to handle the edit events...again, the loadBeforeSend is not triggered...
Thank you in advance, Serban
$.extend($.jgrid.edit, {
closeAfterEdit: true,
closeAfterAdd: true,
ajaxEditOptions: {
contentType: "application/json"
},
mtype: 'POST',
loadBeforeSend: function(xhr)
{
xhr.setRequestHeader("X-HTTP-Method", "MERGE");
return xhr;
},
serializeEditData: function (data) {
delete data.oper;
return JSON.stringify(data);
}
});
There are no
loadBeforeSend
parameter which you can set by$.jgrid.edit
. The values from$.jgrid.edit
defines default options of editGridRow.To specify the
loadBeforeSend
callback which should be used during the corresponding Ajax request you should useajaxEditOptions
instead and specifybeforeSend
(see $.ajax):