<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: proper way of handling REST with dynamic urls</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/proper-way-of-handling-rest-with-dynamic-urls</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/proper-way-of-handling-rest-with-dynamic-urls/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>migajek on proper way of handling REST with dynamic urls</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/proper-way-of-handling-rest-with-dynamic-urls#p28001</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/proper-way-of-handling-rest-with-dynamic-urls#p28001</guid>
        	        	<description><![CDATA[<p>Hi,</p>
<p>I have configured my jqGrid to have hidden column named "resource_uri".&#160;</p>
<p>When editing or deleting I need to send the proper request (PATCH or DELETE) to the address retrieved from edited grid row.</p>
<p>When creating new record, the url is the same as for the list, however there&#39;s extra "id" field appended (even though the "id" field is marked in colmodel as not editable!) with value of "_empty" which I need to remove (otherwise my backend raises an error!).&#160;</p>
<p>Also, I need to manually delete "oper" field (what if I had "oper" field in my colmodel?!)</p>
</p>
<p>for initialization, I&#39;m doing following:</p>
</p>
<pre> $.extend($.jgrid.edit, {                      
     serializeEditData: function(data) {
        // delete fields which are not part of row data        
        delete data.oper;
        if (data.id == &#39;_empty&#39;)
            delete data.id;  
        return JSON.stringify(data);
     }              
  });
  $.extend($.jgrid.del, {
      mtype: &#39;DELETE&#39;,
      serializeDelData: function() {
      // send empty DELETE request
        return "";
      }
});</pre>
<p>now, there are following options for form editing initialization (navGrid):</p>
<pre>var delOptions = {                                      
	onclickSubmit: function(params, postdata) {
                // retrieve proper url to send request to
                // a bit tricky since the postdata equals to row id here
		params.url = $(this).jqGrid(&#39;getRowData&#39;, postdata).resource_uri;
	}
};
var addOptions = {mtype: "POST"};
var editOptions = {            
		mtype: "PATCH",
		onclickSubmit: function(params, postdata) {
                                // find out row id
                                // VERY tricky!
				var row_id = postdata[$(this).attr(&#39;id&#39;)+&#39;_id&#39;];
				params.url = $(this).jqGrid(&#39;getRowData&#39;, row_id).resource_uri;
		},
}
</pre>
<pre></pre>
<p>it&#39;s tricky to retrieve the row id. it&#39;s also <strong>very inconsistent</strong> as the "id" attribute (with "_empty" value) is present while creating the record (even though it should not be there!), yet - while editing - it&#39;s hard to find out the row id.</p>
</p>
<p><strong>also, I don&#39;t find the onclickSubmit to be the proper place</strong> for providing request url - I suppose it&#39;s not fired when doing inline edition (I haven&#39;t tried it yet)?</p>
</p>
<p><strong>is the API so inconsistent or am I doing it wrong</strong>?  Any suggestions, please? 🙂</p>
</p>
<p>regards, mg</p>
]]></description>
        	        	<pubDate>Thu, 10 Jan 2013 16:23:11 +0200</pubDate>
        </item>
</channel>
</rss>