Note that there are some explanatory texts on larger screens.

plurals
  1. POSerializing jqGrid's edit data to JSON
    primarykey
    data
    text
    <p>After a user edits data in jqGrid, I would like to return a formatted JSON string back to the server to be consumed. Below is a sample of what the server expects to receive: </p> <pre><code>{ "aptitudeArrayList":[ { "skill":"VITS", "value":2, "id":2, "color":"RED" }, { "skill":"GBFM", "value":6, "id":1, "color":"GREEN" }, { "skill":"JSON", "value":4, "id":3, "color":"RED" }, { "skill":"CASTLEROCK", "value":7, "id":4, "color":"RED" } ], "cell":12412, "line":"FIRST_LINE", "name":"Barop", "id":1, "region":"The end", "available":true } </code></pre> <p>Here is a segment of my ColModel:</p> <pre><code>... { name:'cell', label:'Cell #', width:80, align:'center', editable:true, editrules:{required:true, integer:true}, editoptions:{size:10, maxlength:10} }, { name:'available', label:'Available', formatter:'checkbox', width:46, align:'center', editable:true, edittype:'checkbox', editoptions:{value:"true:false"} }, { name:"vits.value", label:'VITS', width:300, align:'center', editable:true, jsonmap:"aptitudeArrayList.0.value" }, { name:"vits.color", editable:true, jsonmap:"aptitudeArrayList.0.color" } ... </code></pre> <p>Here are the Edit options: <em>(I commented out postdata as its not needed as of now)</em></p> <pre><code>var editOptions = { onclickSubmit:function (params, postdata) { params.url = URL + '/'; //+ postdata.id; } }; </code></pre> <p>After the edit is called, the data is sent to this function:</p> <pre><code>$.extend($.jgrid.edit, { closeAfterEdit:true, closeAfterAdd:true, ajaxEditOptions:{ contentType:"application/json" }, mtype:'PUT', serializeEditData:function (data) { delete data.oper; return JSON.stringify(data); } }); </code></pre> <p>The inadequate code above returns this JSON:</p> <pre><code>{ "id":"1", "name":"Barop", "region":"The end", "line":"FIRST_LINE", "cell":"12412", "available":"true", "vits.value":"2", "vits.color":"RED" ... } </code></pre> <p>When I attach the debugger I find that <code>data</code> contains: <code>dataObject { id="1", name="Barop", region="The end", ... vits.value="2", vits.color="RED"}</code> It seems it is getting the keys from the <code>name</code> attribute in jqGrid. </p> <p>How would I go about serializing my data to a format that the server requires?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload