<?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: Edit Sample code</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/edit-sample-code</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/edit-sample-code/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>YamilBracho on Edit Sample code</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/edit-sample-code#p2956</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/edit-sample-code#p2956</guid>
        	        	<description><![CDATA[<p>Thanks a lot..!</p>
]]></description>
        	        	<pubDate>Thu, 06 Nov 2008 12:41:53 +0200</pubDate>
        </item>
        <item>
        	<title>gmeader on Edit Sample code</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/edit-sample-code#p2935</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/edit-sample-code#p2935</guid>
        	        	<description><![CDATA[<p>Example code to save the results of editRow to a database using PHP.</p>
<p>Add this to your jqGrid parameters:</p>
<p><span class="sfcode">editurl: &#39;example.php&#39;,</span></p>
<p>Here&#39;s a function to enable the row for editing when it is clicked on (see examples in jqGrid manual for editRow method):</p>
<p><input type='button' class='sfcodeselect' name='sfselectit9732' value='Select Code' data-codeid='sfcode9732' /></p>
<div class='sfcode' id='sfcode9732'>onSelectRow: function(id){<br />&#160;&#160;&#160; if(id &#38;&#38; id!==lastSel){ <br />&#160;&#160;&#160; &#160;&#160;&#160; jQuery(&#39;#list2&#39;).restoreRow(lastSel); <br />&#160;&#160;&#160; &#160;&#160;&#160; jQuery(&#39;#list2&#39;).editRow(id, true,on_edit,checksave);<br />&#160;&#160;&#160; &#160;&#160;&#160; lastSel=id; <br />&#160;&#160;&#160; }<br />}</div>
<p>Here are the two functions required by editRow() because keys is true. checksave() is the succesfunc and on_edit() is the oneditfunc.</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7818' value='Select Code' data-codeid='sfcode7818' /></p>
<div class='sfcode' id='sfcode7818'>function checksave(result) {<br />&#160;&#160;&#160; // check to see if POST returns a good HTTP response<br />&#160;&#160;&#160; if (result.status != 200) {<br />&#160;&#160;&#160; &#160;&#160;&#160; alert(result.statusText);<br />&#160;&#160;&#160; &#160;&#160;&#160;&#160; alert(&#8221;Update failed!&#8221;); <br />&#160;&#160;&#160; &#160;&#160;&#160;&#160; return false;<br />&#160;&#160;&#160; }<br />&#160; // the PHP code sends OK as the first 2 characters if it did the db update successfully<br />&#160; // if the response does not begin with &#39;OK&#39;<br />&#160; // display whatever is returned (probably error msgs) <br />&#160;&#160;&#160; if (result.responseText.substring(0,2) != &#8220;OK&#8221;) {<br />&#160;&#160;&#160; &#160;&#160;&#160; alert(result.responseText);<br />&#160;&#160;&#160; &#160;&#160;&#160; return false;<br />&#160;&#160;&#160; }<br />&#160; return true; <br />}<br />function on_edit(result) {<br />&#160;&#160;&#160; &#160;&#160;&#160; // do nothing<br />&#160;&#160;&#160; &#160; return true; <br />}</div>
<p>Here is the code for example.php:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1745' value='Select Code' data-codeid='sfcode1745' /></p>
<div class='sfcode' id='sfcode1745'>&#60;?php<br />// database connection parameters<br />$db=&#39;&#39;;<br />$host=&#39;&#39;;<br />$user=&#39;&#39;;<br />$pass=&#39;&#39;;</p>
<p>// connect to the MySQL database server <br />$dbh = mysql_connect($host,$user,$pass) or die(&#8221;Connection Error: &#8221; . mysql_error()); <br />// select the database <br />mysql_select_db($db) or die(&#8221;Error selecting &#39;$db&#39; database.&#8221;); </p>
<p>// get clean id<br />$id=mysql_real_escape_string($_POST[&#39;id&#39;]);</p>
<p>$fields = &#39;&#39;;<br />$values = &#39;&#39;;<br />// $exceptions - fields that will not be UPDATEd into table<br />//&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; i.e. &#39;submit, action, &#39;; (note trailing comma and space!)<br />$exceptions=&#39;submit, id, &#39;;</p>
<p>// format input POST fields into SQL syntax for the list of fields and values after SET<br />foreach ($_POST as $field =&#62; $value) {<br />&#160; if (!preg_match(&#8221;/$field, /&#8221;, $exceptions)) {<br />&#160;&#160;&#160; $value = mysql_real_escape_string($value);<br />&#160;&#160;&#160; $fields .= &#8220;$field = &#39;$value&#39;, &#8220;;<br />&#160; }<br />}<br />// remove trailing &#8220;, &#8221; from $fields<br />$fields = preg_replace(&#39;/, $/&#39;, &#39;&#39;, $fields);<br />&#160; <br />$query = &#8220;UPDATE tmpsale SET $fields WHERE id=&#39;$id&#39;&#8221;;</p>
<p>//echo $query;&#160;&#160;&#160; // for debugging, any output text that does not begin with &#8220;OK&#8221; will display in an alert box&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>$result = mysql_query($query); <br />if (!$result) {<br />&#160;&#160; die(&#39;Query error:&#39; . mysql_error());<br />}</p>
<p>if (mysql_affected_rows($dbh) &#62; 0) {<br />&#160; echo &#8220;OK\\n&#8221;;<br />} else {<br />&#160;&#160;&#160; echo &#8220;Update Failed.\\n&#8221;;<br />}<br />?&#62;</p>
</div>
]]></description>
        	        	<pubDate>Wed, 05 Nov 2008 15:57:12 +0200</pubDate>
        </item>
        <item>
        	<title>YamilBracho on Edit Sample code</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/edit-sample-code#p2022</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/edit-sample-code#p2022</guid>
        	        	<description><![CDATA[<p>Hi.</p>
<p>Is there some server side code to applu update to the underlying data ?</p>
<p>I checked the navigarot sample but the someurl.php does no have code at all just an empty php program</p>
<p>TIA</p></p>
]]></description>
        	        	<pubDate>Fri, 12 Sep 2008 09:28:14 +0300</pubDate>
        </item>
</channel>
</rss>