<?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: small improvements in $.ajax which load grid contain</title>
	<link>http://www.trirand.com/blog/?page_id=393/bugs/small-improvements-in-ajax-which-load-grid-contain</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/bugs/small-improvements-in-ajax-which-load-grid-contain/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>OlegK on small improvements in $.ajax which load grid contain</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/small-improvements-in-ajax-which-load-grid-contain#p24716</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/small-improvements-in-ajax-which-load-grid-contain#p24716</guid>
        	        	<description><![CDATA[<p>Hello Tony,</p>
<p>I have some small suggestion to improve in the code of <em>grid.base.js</em> in the call of <strong>$.ajax</strong> (see the lines <a href="https://github.com/tonytomov/jqGrid/blob/v4.1.2/js/grid.base.js#L1687-1710" target="_blank">1687-1710</a>).</p>
<p>1) Add the second parameter to the <strong>beforeSend</strong> callback and forward it to <strong>loadBeforeSend</strong>:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit9517' value='Select Code' data-codeid='sfcode9517' /></p>
<div class='sfcode' id='sfcode9517'>beforeSend: function (xhr<strong>, settings</strong>) {<br />&#160; &#160; beginReq();<br />&#160; &#160; if ($.isFunction(ts.p.loadBeforeSend)) { ts.p.loadBeforeSend.call(ts, xhr<strong>, settings</strong>); }<br />}&#160;</div>
<p>It will simplify implementation of <strong>loadBeforeSend</strong> for example in case of setting custom authentication headers.</p>
<p>2) Include additional event <strong>beforeResponseProcessing</strong> which will be called directly at the begining of&#160;<strong>success</strong> callback:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7868' value='Select Code' data-codeid='sfcode7868' /></p>
<div class='sfcode' id='sfcode7868'>success: function (data, st<strong>, xhr</strong>) {<br />&#160; &#160; <strong>if ($.isFunction(ts.p.beforeResponseProcessing)) {<br />&#160; &#160; &#160; &#160; ts.p.beforeResponseProcessing.call(ts, data, st, xhr);<br />&#160; &#160; }</strong><br />&#160; &#160; if (dt === &#34;xml&#34;) { addXmlData(data, ts.grid.bDiv, rcnt, npage &#62; 1, adjust); }<br />&#160; &#160; ...&#160;</div>
<p>The new event (callback) can gives more flexibility in the usage of jqGrid.</p>
<p>Just two examples where it can be usefull:</p>
<p>a) I have grids where many columns with chechboxes exist. Depend on <em>data contain</em> it can be very usefull to hide some columns where in full grid contain the chechboxes in the columns have false (uncheched). If allow to show only important information. I used <strong>userdata</strong> to send to jqGrid information which columns should be hidden. If one hide the columns <em>before</em> filling of the grid (in the new <strong>beforeResponseProcessing</strong>) the web browser can caclulate grid width abd the whole page layout more effectively. If I hide the columns one after the another inside of <strong>loadComplete</strong> the web browser have more work and grid work slowly.</p>
<p>b) Sometine one uses <strong>datatype</strong> as the function only to have simple way to make modification in the grid response (some decoding of data or creating an additional column based of other columns) <em>before</em> forwarding the data from the server to jqGrid. The introduction of new <strong>beforeResponseProcessing</strong>&#160;callback parameter will make the usage of <strong>datatype</strong>&#160;as the function unneeded in the case.</p>
<p>3) Include the code of <strong>success</strong> and <strong>error</strong> callbacks&#160;before</p>
<p><input type='button' class='sfcodeselect' name='sfselectit5346' value='Select Code' data-codeid='sfcode5346' /></p>
<div class='sfcode' id='sfcode5346'>endReq();</div>
<p>in the <strong>try {...} catch(ex) {}</strong> block. It will make hiding of loading div <em>work allways</em> even if some errors occuer. One can additionally include an alert or some other error message (till to calling user callback like <strong>loadError</strong>) in the catch block. Alternatively one can move <strong>endReq();</strong>&#160;from both&#160;<strong>success</strong>&#160;and&#160;<strong>error</strong>&#160;callbacks&#160;in the additional <strong>complete</strong> callback. The small disadvantage of the way will be unblocking of grid (or hiding of loading div) at the <em>beginning</em> of filling of jqGrid and calling of <strong>loadComplete</strong> handler. This can change the behavier of the user GUI of jqGrid.</p>
<p>Best regards<br />Oleg&#160;</p>
]]></description>
        	        	<pubDate>Thu, 22 Sep 2011 12:57:14 +0300</pubDate>
        </item>
</channel>
</rss>