<?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: method mergeJSONData</title>
	<link>http://www.trirand.com/blog/?page_id=393/feature-request/method-mergejsondata</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/feature-request/method-mergejsondata/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>AndzinSan on method mergeJSONData</title>
        	<link>http://www.trirand.com/blog/?page_id=393/feature-request/method-mergejsondata#p21793</link>
        	<category>Feature Request</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/feature-request/method-mergejsondata#p21793</guid>
        	        	<description><![CDATA[<p>Hi,</p>
<p>I am using jqgrid for loading huge table of datas, thousands of rows. But for better performance I wand to load this huge table only one time - when site is loaded, and then periodic check server for newly added records after user load this huge table, but only this new records, not all, and then merge first time loaded json object with newly loaded records.</p>
<p>So i modyfi grid.base.js file:</p>
</p>
<p>2line around 589 before this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit944' value='Select Code' data-codeid='sfcode944' /></p>
<div class='sfcode' id='sfcode944'>var p = $.extend(true,{</div>
<p>add this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit3058' value='Select Code' data-codeid='sfcode3058' /></p>
<div class='sfcode' id='sfcode3058'>var updateJSON = {};</div>
</p>
<p>2line around 688 before this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7518' value='Select Code' data-codeid='sfcode7518' /></p>
<div class='sfcode' id='sfcode7518'>_index : {},</div>
<p>add this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2103' value='Select Code' data-codeid='sfcode2103' /></p>
<div class='sfcode' id='sfcode2103'>dataUpdateJSON : false,</div>
</p>
<p>2line around 1180 before this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7908' value='Select Code' data-codeid='sfcode7908' /></p>
<div class='sfcode' id='sfcode7908'>addJSONData = function(data,t, rcnt, more, adjust) {</div>
<p>add this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7003' value='Select Code' data-codeid='sfcode7003' /></p>
<div class='sfcode' id='sfcode7003'>mergeJSONData = function(data){if(ts.p.dataUpdateJSON == true){/*data = updateJSON.data;here you must write some code do merge data and updateJSON.data*/t = updateJSON.bDiv;rcnt = updateJSON.rcnt;npage = updateJSON.npage;adjust = updateJSON.adjust;lc = updateJSON.lc;pvis = updateJSON.pvis;ts.p.datatype = &#34;json&#34;;addJSONData(data,t,rcnt,npage&#62;1,adjust);if(lc) { lc.call(ts,data); }if (pvis) { ts.grid.populateVisible(); }if( ts.p.loadonce &#124;&#124; ts.p.treeGrid) {ts.p.datatype = &#34;local&#34;;}data=null;endReq();}},</div>
</p>
<p>2line around 1630 (after edit previous it can by different) before this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit8151' value='Select Code' data-codeid='sfcode8151' /></p>
<div class='sfcode' id='sfcode8151'>if(dt === &#34;xml&#34;) { addXmlData(data,ts.grid.bDiv,rcnt,npage&#62;1,adjust); }</div>
<p>add this:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1764' value='Select Code' data-codeid='sfcode1764' /></p>
<div class='sfcode' id='sfcode1764'>if(ts.p.dataUpdateJSON === true) { updateJSON.data = data;updateJSON.bDiv = ts.grid.bDiv;updateJSON.rcnt = rcnt;updateJSON.npage = npage;updateJSON.adjust = adjust;if(lc) { updateJSON.lc = lc; };if(pvis) { updateJSON.pvis = pvis;};}</div>
</p>
<p>Ok, adding done, now edit your setup:</p>
<p>in your jqgrid set up new option "dataUpdateJSON" to true - default is false; true enable this little trick</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit6232' value='Select Code' data-codeid='sfcode6232' /></p>
<div class='sfcode' id='sfcode6232'>dataUpdateJSON: true,</div>
<p>set up option loadComplete to function witch will call your custom reload grid function, example: reload_grid();</p>
<p>sample:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit8399' value='Select Code' data-codeid='sfcode8399' /></p>
<div class='sfcode' id='sfcode8399'>
<p>var grid_reload;</p>
<p>var grid_reload_time = 3000;</p>
<p>function reload_grid()</p>
<p>{</p>
<p>clearInterval(grid_reload);</p>
<p>grid_reload = setInterval(function()</p>
<p>{</p>
<p>var mygrid = jQuery(&#34;#grid&#34;)[0];</p>
<p>$.ajax( url:&#34;your ajax url&#34;,</p>
<p>type:&#34;POST&#34;,</p>
<p>dataType: &#34;json&#34; ,</p>
<p>data: &#34;your data to server&#34;,</p>
<p>success:function(data,st)</p>
<p>{</p>
<p>mygrid.mergeJSONData(data);</p>
<p>});</p>
<p>},grid_reload_time);</p>
<p>};</p>
</div>
<p>WARNING: I test this only with my configuration:</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7582' value='Select Code' data-codeid='sfcode7582' /></p>
<div class='sfcode' id='sfcode7582'>
<p>loadonce: true,</p>
<p>rowTotal: -1,</p>
<p>datatype: &#34;json&#34;,</p>
</div>
<p>and for now I dont have writed script code for merge two datas objects, but you can write yourself. I will post one ASAP.</p>
</p>
<p>So i hope that this is good idea.</p>
]]></description>
        	        	<pubDate>Sat, 22 Jan 2011 23:15:58 +0200</pubDate>
        </item>
</channel>
</rss>