<?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: inlinedit - saveRow modified</title>
	<link>http://www.trirand.com/blog/?page_id=393/discussion/inlinedit-saverow-modified</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/discussion/inlinedit-saverow-modified/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>tony on inlinedit - saveRow modified</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/inlinedit-saverow-modified#p8042</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/inlinedit-saverow-modified#p8042</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>You can use the&#160;info_dialog function for this purpose. Just look in grid.common.js.</p>
</p>
<p>Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Mon, 27 Jul 2009 02:26:02 +0300</pubDate>
        </item>
        <item>
        	<title>Janooo on inlinedit - saveRow modified</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/inlinedit-saverow-modified#p8026</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/inlinedit-saverow-modified#p8026</guid>
        	        	<description><![CDATA[<p>Hi Tony,<br />Great work, thanks a million&#8230;</p>
<p>I have a typical row edit situation:<br />You edit a line; <br />The server saves;<br />If the save is a success then update row timestamp with a new value;<br />If the save failed because the row got updated by another user/process <br />then restore the row with the new values and display a message.</p>
<p>The success server response:<br />{ "rowData" : { "timestamp":"2009-07-25 16:27:39.860" }}</p>
<p>The failure server response:<br />{ "jqGridMessage" : "The record has been changed by another process. No changes were saved.", <br />"rowData" : { "long_name":"Joe Black", "timestamp":"2009-01-06 12:00:01.987" }}</p>
<p>I had a aftersave function defined at the &#39;editRow&#39;.<br />Well it works fine but if the &#39;saveRow&#39; can handle it even better and I don&#39;t have to do anything at &#39;editRow&#39;.<br />So, I slightly modified the &#39;saveRow&#39; function and its ajax call looks like this now:</p>
<p>$.ajax({ url: url,<br />&#160;&#160;&#160; data: tmp,<br />&#160;&#160;&#160; type: "POST",<br />&#160;&#160;&#160; complete: function(res, stat) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (stat === "success") {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var ret;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ($.isFunction(succesfunc)) { ret = succesfunc(res); }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else ret = true;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (ret === true) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; tmp = $.extend({}, tmp, tmp2);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $($t).setRowData(rowid, tmp);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $(ind).attr("editable", "0");<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (var k = 0; k &#60; $t.p.savedRow.length; k++) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ($t.p.savedRow[k].id === rowid) { fr = k; break; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; };<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (fr &#62;= 0) { $t.p.savedRow.splice(fr, 1); }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // start of the new code<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (isJson(res.responseText)) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var jsonResponse = eval(&#39;(&#39; + res.responseText + &#39;)&#39;);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (jsonResponse[&#39;rowData&#39;]) $($t).setRowData(rowid, jsonResponse[&#39;rowData&#39;]);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (jsonResponse[&#39;jqGridMessage&#39;]) jqgrid_message(jsonResponse[&#39;jqGridMessage&#39;]);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // end of the new code<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ($.isFunction(aftersavefunc)) { aftersavefunc(rowid, res.responseText); }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else { $($t).restoreRow(rowid, afterrestorefunc); }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160; },</p>
<p>Here are functions required for the jqgrid_message.</p>
<p>function create_div(oD) {<br />&#160;&#160;&#160; if (oD[&#39;div_id&#39;] &#38;&#38; !$(&#39;#&#39; + oD[&#39;div_id&#39;]).length) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; var oDiv = document.createElement(&#39;div&#39;);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (oD[&#39;cssText&#39;]) oDiv.style.cssText = oD[&#39;cssText&#39;];<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (oD[&#39;title&#39;]) oDiv.title = oD[&#39;title&#39;];<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; oDiv.id = oD[&#39;div_id&#39;];<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; document.body.appendChild(oDiv);<br />&#160;&#160;&#160; }<br />}</p>
<p>function isJson(string) {<br />&#160;&#160;&#160; return typeof (eval("(" + string + ")")) == &#39;object&#39;;<br />}<br />// or this one<br />jQuery.isJson = function(str) {<br />&#160;&#160;&#160; if (jQuery.trim(str) == &#39;&#39;) return false;<br />&#160;&#160;&#160; str = str.replace(/\\\\./g, &#39;@&#39;).replace(/"[^"\\\\\\n\\r]*"/g, &#39;&#39;);<br />&#160;&#160;&#160; return (/^[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]*$/).test(str);<br />} </p>
<p>function jqgrid_message(msg){<br />&#160;&#160;&#160; if (!$(&#39;#jqgrid_message&#39;).length) {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; create_div({ &#39;div_id&#39;: &#39;jqgrid_message&#39;, &#39;cssText&#39;: &#39;display: none\\;&#39;, &#39;title&#39;: &#39;jqGrid Message&#39; });<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; $(&#39;#jqgrid_message&#39;).html(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#39;&#60;p&#62;&#60;span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"&#62;&#60;/span&#62;\\<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;span id="jqgrid_message_text"&#62;&#38;nbsp;&#60;/span&#62;&#60;/p&#62;&#39;<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; );<br />&#160;&#160;&#160; }<br />&#160;&#160;&#160; $(&#39;#jqgrid_message_text&#39;).html(msg);<br />&#160;&#160;&#160; $(&#39;#jqgrid_message&#39;).dialog({<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; bgiframe: true,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; modal: true,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; width: 450,<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; buttons: {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Ok: function() {<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $(this).dialog(&#39;destroy&#39;);<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; },<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; close: function(event, ui) { $(this).dialog(&#39;destroy&#39;); }<br />&#160;&#160;&#160; });<br />}</p>
<p>If the modified &#39;saveRow&#39; function makes sense, please, feel free to include it in the jqGrid.<br />I created the &#39;jqgrid_message&#39; function as a jQuery modal dialog. <br />Maybe a jqGrid method &#39;message&#39; or &#39;dialog&#39;&#160; that opens in the middle of a grid would be useful. <br />Just a new item on the wish list <img class="spSmiley" style="margin:0" title="Smile" src="/blog/wp-content/forum-smileys/sf-smile.gif" alt="Smile" /></p>
<p>Regards,<br />Jano</p>
]]></description>
        	        	<pubDate>Sat, 25 Jul 2009 16:36:01 +0300</pubDate>
        </item>
</channel>
</rss>