<?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: trigger.("reloadGrid") not working when grid called from ajax function</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/trigger-reloadgrid-not-working-when-grid-called-from-ajax-function</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/trigger-reloadgrid-not-working-when-grid-called-from-ajax-function/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>RustedBucket on trigger.("reloadGrid") not working when grid called from ajax function</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/trigger-reloadgrid-not-working-when-grid-called-from-ajax-function#p25487</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/trigger-reloadgrid-not-working-when-grid-called-from-ajax-function#p25487</guid>
        	        	<description><![CDATA[<p>My grid code is below. Basically I call it from an ajax function in order to use the response to get row data in the result. Unfortunately this has broken the reload trigger when a cell is updated.</p>
<p><input type='button' class='sfcodeselect' name='sfselectit4838' value='Select Code' data-codeid='sfcode4838' /></p>
<div class='sfcode' id='sfcode4838'>
<p>&#60;div id="gridwrapper"&#62;<br />&#60;table id="bwdetail" style="width:100%;"&#62;&#60;/table&#62; <br />&#60;div id="pager"&#62;&#60;/div&#62;<br />&#60;/div&#62;</p>
<p>&#60;script src="/js/jqGrid/src/grid.celledit.js" type="text/javascript"&#62; &#60;/script&#62;</p>
<p>&#60;script type="text/javascript"&#62;<br />var vendor_id = &#39;&#60;?php echo Zend_Controller_Front::getInstance()-&#62;getRequest()-&#62;getParam( "id", null ); ?&#62;&#39;;</p>
<p>var myGrid = $(&#39;#bwdetail&#39;);<br />var ret;<br />var theight;</p>
<p>jQuery(document).ready(function(){f<br />&#160;&#160; &#160;<br />&#160;&#160; &#160;$.ajax({<br />&#160;&#160; &#160;&#160;&#160;&#160; type: "POST",<br />&#160;&#160; &#160;&#160;&#160;&#160; url:&#39;/air/buyworksheet/detailgrid/id/&#39;+vendor_id,<br />&#160;&#160; &#160;&#160;&#160;&#160; datatype: "json",<br />&#160;&#160; &#160;&#160;&#160;&#160; success: function (data, status) {<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var tdata = JSON.stringify(data);<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var trows = data.records;<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(trows &#62;= 15) {<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160; &#160;if (innerHeight&#62;=600) var theight = 390; else var theight = 250;<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var theight=&#39;auto&#39;;<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; renderGrid(trows, theight, tdata);<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; resize_the_grid();<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jQuery("#bwdetail").jqGrid(&#39;navGrid&#39;, &#39;#pager&#39;, {add:false, view:false, edit:false, del:false, search:true,refresh:true});<br />&#160;&#160; &#160;&#160;&#160;&#160; }<br />&#160;&#160; &#160;});</p>
<p>&#160;&#160; &#160;function refreshGrid() {<br />&#160;&#160; &#160;&#160;&#160; &#160;jQuery("#bwdetail").trigger("reloadGrid");<br />&#160;&#160; &#160;}&#160;&#160; &#160;<br />&#160;&#160; &#160;<br />&#160;&#160; &#160;function renderGrid(trows, theight, tdata) {</p>
<p>&#160;&#160; &#160;&#160;&#160; &#160;jQuery("#bwdetail").jqGrid({<br />&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; datatype: "jsonstring",<br />&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; datastr: tdata,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;height:theight,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;colNames:[&#39;id&#39;,&#39;Item&#39;, &#39;UPC&#39;, &#39;Description&#39;, &#39;Sales Qty.&#39;, &#39;Need&#39;, &#39;Order Qty.&#39;, &#39;Min. Qty.&#39;, &#39;Purchase U/M&#39;, &#39;Ext. Cost&#39;],<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;colModel:[<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;id&#39;,index:&#39;id&#39;, width:25, align:"center", sorttype:&#39;int&#39;,hidden:true},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;item_number&#39;,index:&#39;item_number&#39;, width:20, align:"center", sorttype:&#39;int&#39;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;barcode&#39;,index:&#39;barcode&#39;, width:25, align:"center",sorttype:&#39;int&#39;},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;description&#39;,index:&#39;description&#39;, width:75},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;quantity&#39;,index:&#39;quantity&#39;, width:15, align:"center"},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;need&#39;,index:&#39;need&#39;, width:15, align:"center",editable:true,classes:&#39;activecell&#39; },<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;order_qty&#39;,index:&#39;order_qty&#39;, width:15, align:"center",editable:true,classes:&#39;activecell&#39; },<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;minimum_purchase_quantity&#39;,index:&#39;minimum_purchase_quantity&#39;, width:15, align:"center"},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;measurement_code&#39;,index:&#39;measurement_code&#39;, width:20, align:"center"},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{name:&#39;cost&#39;,index:&#39;cost&#39;, width:15, align:"center",formatter: &#39;currency&#39;, formatoptions:{decimalSeparator:".", thousandsSeparator: ",", decimalPlaces: 2, prefix: "$ "}},<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;],<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;rowNum: trows,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;rownumbers: true, <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;rownumWidth: 40,&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;pager: &#39;#pager&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;altRows: true,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;altclass:&#39;myAltRowClass&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160; &#160;&#160;&#160; &#160;gridview: true,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; viewrecords: true,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; footerrow: true, <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; userDataOnFooter: true,&#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; sortorder: "asc",<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; autowidth: true,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; shrinkToFit: true,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; cellEdit: true,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; cellsubmit: &#39;clientArray&#39;,<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; afterSaveCell : function(rowid,name,val,iRow,iCol) {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;var ret = jQuery("#bwdetail").jqGrid(&#39;getRowData&#39;,rowid); </p>
<p>&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;if(name == &#39;need&#39;) { $.post("/air/buyworksheet/updategrid/id/"+ret.id+"/bc/"+ret.item_number+"/n/"+ret.need); refreshGrid();} <br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;if(name == &#39;order_qty&#39;) { $.post("/air/buyworksheet/updatequantity/id/"+ret.id+"/bc/"+ret.item_number+"/q/"+ret.order_qty); refreshGrid();}</p>
<p>&#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;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;});<br />&#160;&#160; &#160;}</p>
<p>&#160;&#160; &#160;function resize_the_grid() { $(&#39;#bwdetail&#39;).fluidGrid({base:&#39;#gridwrapper&#39;, offset:-20}); }</p>
<p>&#160;&#160; &#160;$(window).resize(resize_the_grid);<br />});</p>
<p>&#60;/script&#62;</p>
</div>
<p>Now if I replace the refreshGrid function with this one:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit5142' value='Select Code' data-codeid='sfcode5142' /></p>
<div class='sfcode' id='sfcode5142'>
<p>&#160;&#160;&#160; function refreshGrid() {</p>
<p> &#160;&#160; &#160;&#160;&#160; &#160;$(&#39;#bwdetail&#39;).jqGrid(&#39;GridUnload&#39;);</p>
<p> &#160;&#160; &#160;&#160;&#160; &#160;$.ajax({<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; type: "POST",<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; url:&#39;/air/buyworksheet/detailgrid/id/&#39;+vendor_id,<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; datatype: "json",<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; success: function (data, status, xhr) {<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var tdata = JSON.stringify(data);<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var trows = data.records;<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(trows &#62;= 15) {<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160; &#160;if (innerHeight&#62;=600) var theight = 390; else var theight = 250;<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var theight=&#39;auto&#39;;<br /> &#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; &#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; renderGrid(trows, theight, tdata);<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; resize_the_grid();<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jQuery("#bwdetail").jqGrid(&#39;navGrid&#39;, &#39;#pager&#39;,  {add:false, view:false, edit:false, del:false,  search:true,refresh:true});<br /> &#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160;&#160; }<br /> &#160;&#160; &#160;&#160;&#160; &#160;});<br /> &#160;&#160; &#160;&#160;&#160; &#160;<br /> }</p>
</div>
<p>This works but obviously is reloads the entire grid. Not necessarily a problem but you visibly see the grid unload then reload vs. before when the whole grid was loaded from one function you didn&#39;t notice any flicker at all.</p>
</p>
<p>Any ideas on how to correct this?</p>
]]></description>
        	        	<pubDate>Tue, 20 Dec 2011 20:00:02 +0200</pubDate>
        </item>
</channel>
</rss>