<?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: Discussion about modifications i made to the "columnChooser" method.</title>
	<link>http://www.trirand.com/blog/?page_id=393/discussion/discussion-about-modifications-i-made-to-the-columnchooser-method</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/discussion-about-modifications-i-made-to-the-columnchooser-method/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>nelsonm on Discussion about modifications i made to the "columnChooser" method.</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/discussion-about-modifications-i-made-to-the-columnchooser-method#p28231</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/discussion-about-modifications-i-made-to-the-columnchooser-method#p28231</guid>
        	        	<description><![CDATA[<p>First of all, I&#39;m greatfull that a way to dynamically sort and hide/show columns via the "columnChooser" method exists.</p>
</p>
<p>However, it seems a bit awkward and incomplete in it&#39;s functionality in the "apply_perm" option function within the "columnChooser" method.</p>
<p>1. if you don&#39;t use the "done" option, the method remaps the columns using the default jqgrid remapColumns method attached to the "done" option in the "columnChooser" method&#160;extended options. &#160;If you do use the "done", you have to execute the jqgrid remapColumns method manually in a user defined "done" callback function. &#160;However, hiding and showing columns is always managed within the "apply_perm" option function regardless of whether a user defined "done" callback function is defined. &#160;It seems to me that the remapping and visibility of the columns should always be handled within the "apply_perm" option function regardless of whether a user defined "done" callback function is defined.</p>
<p>2. the "columnChooser"&#160;method always makes the permutation array available&#160;as a parameter of the user defined "done" callback function. &#160;This is most usefull for storing and retrieving the column order via SQL. &#160;However, there is no array available that contains the visibility of the columns to use in storing and retrieving the column visibility via SQL.</p>
</p>
<p>When i reload my site, i find it usefull to be able to retrieve and restore both the permutation and visibility of all jqGRID columns.</p>
</p>
<p>So, i made a few modifications to the&#160;columnChooser&#39;s&#160;"apply_perm" option function to make make its functionallity more consistant and usefull.</p>
</p>
<p>Here are the modifications i made (in <span style="color: #000000;">black</span>). &#160;Your comments are welcome. (It would also be nice if columns in the hidden select list on columnChooser could be added back to the visible select list in the same location it was removed from in the visible select list. TBD)</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1360' value='Select Code' data-codeid='sfcode1360' /></p>
<div class='sfcode' id='sfcode1360'>
<p>&#34;apply_perm&#34; : function() {</p>
<p>&#160; &#160;$(&#39;option&#39;,select).each(function() {</p>
<p>&#160; &#160; &#160; if (this.selected) {</p>
<p>&#160; &#160; &#160; &#160; &#160;self.jqGrid(&#34;showCol&#34;, colModel[this.value].name);</p>
<p>&#160; &#160; &#160; } else {</p>
<p>&#160; &#160; &#160; &#160; &#160;self.jqGrid(&#34;hideCol&#34;, colModel[this.value].name);</p>
<p>&#160; &#160; &#160; }</p>
<p>&#160; &#160;});</p>
</p>
<p><strong><span style=&#34;&#34;&#34;&#34;&#34;&#34;&#34;color:&#34;&#34;&#34;&#34;&#34;&#34;>&#160; &#160;var visi = [];</span></strong></p>
<p><strong><span style=&#34;&#34;&#34;&#34;&#34;&#34;&#34;color:&#34;&#34;&#34;&#34;&#34;&#34;>&#160; &#160;$.each(colModel, function(i){visi.push(!this.hidden);});</span></strong></p>
</p>
<p>&#160; &#160;var perm = [];</p>
<p>&#160; &#160;//fixedCols.slice(0);</p>
<p>&#160; &#160;$(&#39;option:selected&#39;,select).each(function() { perm.push(parseInt(this.value,10)); });</p>
<p>&#160; &#160;$.each(perm, function() { delete colMap[colModel[parseInt(this,10)].name]; });</p>
<p>&#160; &#160;$.each(colMap, function() {</p>
<p>&#160; &#160; &#160; var ti = parseInt(this,10);</p>
<p>&#160; &#160; &#160; perm = insert(perm,ti,ti);</p>
<p>&#160; &#160;});</p>
</p>
<p><strong><span style=&#34;&#34;&#34;&#34;&#34;&#34;&#34;color:&#34;&#34;&#34;&#34;&#34;&#34;>&#160; &#160;self.jqGrid(&#34;remapColumns&#34;, perm, true);</span></strong></p>
</p>
<p>&#160; &#160;if (opts.done) {</p>
<p>&#160; &#160; &#160; opts.done.call(self, perm<strong><span style=&#34;&#34;&#34;&#34;&#34;&#34;&#34;color:&#34;&#34;&#34;&#34;&#34;&#34;>, visi</span></strong>);</p>
<p>&#160; &#160;}</p>
<p>},</p>
</div>
<p>Now the user defined callback function has access to both the permutation and visibility arrays available to store and restore via SQL as follows:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit9665' value='Select Code' data-codeid='sfcode9665' /></p>
<div class='sfcode' id='sfcode9665'>
<p>function setGridState(gid,pid,caption,title){</p>
<p>&#160; &#160;// setup print button in the grid top navigation bar.</p>
<p>&#160; &#160;$(&#39;#&#39;+gid).jqGrid(&#39;navSeparatorAdd&#39;, &#39;#&#39;+gid+&#39;_toppager_left&#39;, {sepclass :&#39;ui-separator&#39;});</p>
<p>&#160; &#160;$(&#39;#&#39;+gid).jqGrid(&#39;navButtonAdd&#39;,    &#39;#&#39;+gid+&#39;_toppager_left&#39;, {caption: caption, title: title, position: &#39;last&#39;, buttonicon: &#39;ui-icon-wrench&#39;, onClickButton : function (){$(&#39;#&#39;+gid).jqGrid(&#39;columnChooser&#39;,{done: done});/* HideColumns(&#39;#colchooser_&#39;,gid); */}});</p>
</p>
<p>&#160; &#160;// OK or Cancel button are clicked.</p>
<p>&#160; &#160;var done = function(perm<strong><span style=&#34;&#34;&#34;color:&#34;&#34;>,visi</span></strong>){</p>
<p>&#160; &#160; &#160; // OK was clicked.</p>
<p>&#160; &#160; &#160; if (perm){</p>
<p>&#160; &#160; &#160; &#160; &#160;// maintain proper grid width.</p>
<p>&#160; &#160; &#160; &#160; &#160;$(&#39;#&#39;+gid).jqGrid(&#39;setGridWidth&#39;,SavedGridWidth[gid]);</p>
</p>
<p>&#160; &#160; &#160; &#160; &#160;// <strong><span style=&#34;&#34;color:&#34;>save new column order and visability in database.</span></strong></p>
<p>&#160; &#160; &#160; &#160; &#160;SaveGridState(gid,perm<strong><span style=&#34;&#34;&#34;color:&#34;&#34;>,visi</span></strong>);</p>
</p>
<p>&#160; &#160; &#160; }else{</p>
<p>&#160; &#160; &#160; &#160; &#160;// we can do some action in case of &#34;Cancel&#34; button clicked</p>
<p>&#160; &#160; &#160; }</p>
<p>&#160; &#160;}</p>
<p>}</p>
</div>
<p>What do you all think?</p></p>
]]></description>
        	        	<pubDate>Thu, 07 Feb 2013 04:05:11 +0200</pubDate>
        </item>
</channel>
</rss>