I'm using Oleg's free jqGrid. After my form editing, I am trying to wrap my POST data, so that in PHP I get a nice array like:
Array(
oper => edit,
data => Array(
foo => '123',
bar => 'xyz',
...
)
)
where the operator and the data on which it operates are nicely separated.
My intuitive approach would have been something like:
beforeSubmit: function( postdata, formid ) {
var d = {};
d.data = postdata;
console.log( d );
postdata = d;
return( [true, ''] );
}
Unfortuntely this doesn't work; console.log(d) nicely prints the desired result, but postdata is not changed. I am not well-versed in javascript, but I suspect the global postdata is not changed from within the function, and unfortunately the function doesn't allow me to return it.
Any suggestions on how to solve this. It is a minor problem, but I just thought that it looked more structured, and would be more maintainable, to have the clean separation between operator and its data.
Thank you.
The callback
beforeSubmitisn't the best choice in your case. Instead of that I'd recommend you to useserializeEditDatacallback, which you can define either as the option of form editing (inside offormEditingparameter of jqGrid) or as the parameter of jqGrid. The callback getpostdataas the only parameter and it should return the modified object of JSON string, which should be sent to the server. The code could be about the following