
I've started to implement the editing capability of jqGrid in APEX. After looking at the documentation briefly, I struggled to understand how I could change the POST parameters when rows were saved, as by default I was getting this:
And what I actually needed, was them in the form of x01, x02 etc. So after a bit of searching, looking at the actual code and then back at the wiki, everything was pointing at a non-existent function called "serializeRowData". I then realized that when we create our jqGrid we can pass this function as one of the config parameters just like we do for "onSelectRow".
For simplicity and the fact that APEX onDemnad processes only cater for 10 variables I decided to pass the data back in an actual JSON object, well a string representation of it to be precise, as I'll post process it server side with PLJSON. All I needed to do was convert my postdata object into a string and convert it back to a JSON object and I got a little help from json2.js for that. Here's the solution:
jQuery("#tableid").jqGrid({
....
serializeRowData: function(postdata){
return { x01: JSON.stringify(postdata) };
}
....
});
Which results in the following:
The next step was to add a new member function to the JSON type in PLJSON to extract the column names to use in the query, i.e. as they are the keys. There's no existing functionality that provides this, but it was simple as the following:
member function get_keys return json_list as
keys json_list;
indx pls_integer;
begin
keys := json_list();
indx := json_data.first;
loop
exit when indx is null;
keys.add_elem(json_data(indx).member_name);
indx := json_data.next(indx);
end loop;
return keys;
end;


