<?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: fixing grid width calculation</title>
	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation</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/fixing-grid-width-calculation/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>OlegK on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22676</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22676</guid>
        	        	<description><![CDATA[<p>Hi Tony,</p>
<p>I found out that the last version of code <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2825" target="_blank">at the end</a> of <strong>showHideCol</strong>&#160;work not correct. To fix the problem one should simplify the code inside of <strong>if(fndh===true)</strong> to the following</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2889' value='Select Code' data-codeid='sfcode2889' /></p>
<div class='sfcode' id='sfcode2889'>if(fndh===true) {<br />&#160;&#160; &#160;if($t.grid.width!==$t.p.tblwidth) {<br />&#160;&#160; &#160; &#160; &#160;$($t).jqGrid(&#34;setGridWidth&#34;,$t.p.shrinkToFit===true?$t.grid.width:$t.p.tblwidth,true);<br />&#160;&#160; &#160;}<br />}&#160;</div>
<p>Best regards<br />Oleg</p>
]]></description>
        	        	<pubDate>Tue, 05 Apr 2011 18:19:32 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22632</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22632</guid>
        	        	<description><![CDATA[<p>OK I see now. You merged the fix more quickly as I posted my comments here. 🙂</p>
<p>Do you read <a href="https://github.com/tonytomov/jqGrid/commit/5afb95925f29ee57e183314a8835ac053c6cec1a#commitcomment-321116" target="_blank">my comment</a>&#160;in github&#160;to <a href="https://github.com/tonytomov/jqGrid/commit/5afb95925f29ee57e183314a8835ac053c6cec1a" target="_blank">the changes</a>? It seems to me that the change without the line</p>
<p><input type='button' class='sfcodeselect' name='sfselectit338' value='Select Code' data-codeid='sfcode338' /></p>
<div class='sfcode' id='sfcode338'>if(String(ts.p.height).toLowerCase()&#160;===&#160;&#34;auto&#34;)&#160;{&#160;ts.p.height&#160;=&#160;&#34;100%&#34;;&#160;}</div>
<p>is not work (see demos).</p>
<p>If you&#39;ll find the time to look <a href="/blog/?page_id=393/bugs/non-unique-ids-firstprevnextlastsp_1-and-jqgh_colname-used-in-the-pager/" target="_blank">the suggestion</a>&#160;how to fix id duplicates in the pager let me know.</p>
<p>Best regards<br />Oleg&#160;</p>
]]></description>
        	        	<pubDate>Thu, 31 Mar 2011 19:47:32 +0300</pubDate>
        </item>
        <item>
        	<title>tony on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22630</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22630</guid>
        	        	<description><![CDATA[<p>Thanks Oleg.</p>
<p>I have merged the fixes.</p>
<p>I prefer to discuss the changes first and then to make the changes.</p>
<p>The chang from the link you provide is already done.</p>
</p>
<p>Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Thu, 31 Mar 2011 19:32:44 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22629</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22629</guid>
        	        	<description><![CDATA[<p>I posted my suggestions in GitHub <a href="https://github.com/tonytomov/jqGrid/compare/2e433c6fbf...188513c62d" target="_blank">here</a>.</p>
<p>Best regards<br />Oleg</p>
<p>P.S. If the way is better for you I could make all bug fixes or feature requests with the code in GitHub in the same way. I can additionally post in the Bug forum only my comments to the suggested &#160;changes. Schould I post for example <a href="/blog/?page_id=393/bugs/non-unique-ids-firstprevnextlastsp_1-and-jqgh_colname-used-in-the-pager/" target="_blank">this bug report</a> also in the same way?</p>
]]></description>
        	        	<pubDate>Thu, 31 Mar 2011 19:03:29 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22625</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22625</guid>
        	        	<description><![CDATA[<p>OK I will do this in GitHub.</p>
<p>If I past the text in the forum I always verify and modify in HTML mode, but I found one more strange behavior. Till you posted your reply, the <strong>strikethrough&#160;</strong>text was correctly displplayed. After you posted the answer, the <strong>strikethrough&#160;</strong>text become not more <strong>strikethrough</strong>&#160;but are displyed in another color.</p>
<p>Regards<br />Oleg</p>
]]></description>
        	        	<pubDate>Thu, 31 Mar 2011 17:48:55 +0300</pubDate>
        </item>
        <item>
        	<title>tony on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22621</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22621</guid>
        	        	<description><![CDATA[<p>Oleg,</p>
<p>Please do the changes&#160; in GitHub.</p>
</p>
<p>To delete a text open the post switch to HTML mode and enter the del tag</p>
<p>Thanks</p>
<p>Tony</p></p>
]]></description>
        	        	<pubDate>Thu, 31 Mar 2011 17:13:42 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22619</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22619</guid>
        	        	<description><![CDATA[<p>Hi Tony!</p>
<p>I want mention, that now some texts in the code which was displayed as <strong>strikethrough (deleted)</strong> are displayed now as <strong>black</strong>. All lines with <strong>tw&#160;</strong>variable in my code are <strong>strikethrough (deleted)</strong>.</p>
<p>It is very strange what the text editor (or the forum) do.</p>
<p>Oleg</p>
]]></description>
        	        	<pubDate>Thu, 31 Mar 2011 17:05:40 +0300</pubDate>
        </item>
        <item>
        	<title>tony on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22617</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22617</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Thanks Oleg, I will look an test your changes right now and will write you for the <del>result</del></p>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Thu, 31 Mar 2011 16:45:48 +0300</pubDate>
        </item>
        <item>
        	<title>OlegK on fixing grid width calculation</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22561</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/fixing-grid-width-calculation#p22561</guid>
        	        	<description><![CDATA[<p>Hello Tony,</p>
<p>last time you are probably too busy because I receive no feedback from you about my last posts. Nevertheless one more bug with the corresponding fix:</p>
<p>I analysed some problems with wrong width calculation and found out three main reasons for that:</p>
<ol>
<li>The width calculation in <strong>setColWidth</strong> function has some small bugs. There are very close code in <strong>setGridWidth</strong> which works much better and some problems existing in <strong>setColWidth</strong> are fixed here.</li>
<li>On all non-webkit webbrowsers the column width set to the column (from width option of colModel) will be interpret as inner witdth (without border). So if the grid has default setting <strong>shrinkToFit:true</strong> then the <strong>width</strong> value of all non-fixed <strong>colModel</strong> will be imediataly decreased even if there are enough free space for the grid. So from one side the <strong>width</strong> value of <strong>colModel</strong> to set inner width of columns, but then change the value as if one set the outer width.</li>
<li>If the grid has <strong>shrinkToFit:true</strong> option, in the calculation of the shrinked column size will be used only <em>non-hidden</em> columns. The original column sie from the <strong>colModel</strong> definition <span style="text-decoration: underline;">will be ovewritten</span>. If later one make some initially hidden column visible one recalculate the width of every column one more time. Now one use the current reduced size of initially visible columns and compared it with unchanged width of initially hidden column. In the way the proportions between columns will be distorted. I suggest at the begining to save the original value of <strong>width</strong> property of <strong>colMadel</strong> items in another property <strong>widthOrg</strong> and use always the property in the calculations of the shrinked width of columns. In the way the proportions between column widths will stay allways the same as one defined in <strong>colMadel</strong> independend on the order in which the columns will become visible.</li>
</ol>
<p>I prepared the corresponding bug fix with changes in <strong>setColWidth</strong> , <strong>ShowHideCol</strong> and <strong>setGridWidth</strong> functions which I will post later today (about 20 lines of code should be changed).</p>
<p>Tony, in which form you desire that I post the changes: here or in github? If I post it in github it will be easy to make exactly this changes, but if I post my suggestions here you can easier to make some changes in the code.</p>
<p>-----------------------------</p>
<p>OK, Tony here are my suggestions:</p>
<p><strong><span style="text-decoration: underline;">Changes in the function setColWidth:</span></strong> Line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L1868" target="_blank">1868</a>:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit6486' value='Select Code' data-codeid='sfcode6486' /></p>
<div class='sfcode' id='sfcode6486'>var initwidth = 0, brd=ts.p.cellLayout, vc=0, lvc, scw=ts.p.scrollOffset,cw,hs=false,aw<span style=&#34;text-decoration: line-through;&#34;><strong>,tw=0</strong></span>,gw=0,</div>
<p>after the line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L1872" target="_blank">1872</a>-1877&#160;shold be done following:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit4899' value='Select Code' data-codeid='sfcode4899' /></p>
<div class='sfcode' id='sfcode4899'>if(typeof this.hidden === &#39;undefined&#39;) {this.hidden=false;}<br /><strong>cw = intNum(this.width,0);</strong><br /><strong>this.widthOrg = cw; // save the original column width</strong><br />if(this.hidden===false){<br />&#160;&#160; &#160;initwidth += <strong>cw+brd</strong>;<br />&#160;&#160; &#160;if(this.fixed) {<br />&#160;&#160; &#160; &#160; &#160;<span style=&#34;text-decoration: line-through;&#34;><strong>tw += cw;</strong></span><br />&#160;&#160; &#160; &#160; &#160;gw += <strong>cw</strong>+brd;<br />&#160;&#160; &#160;} else {&#160;</div>
<p>The line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L1884" target="_blank">1884</a> should be deleted:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit3747' value='Select Code' data-codeid='sfcode3747' /></p>
<div class='sfcode' id='sfcode3747'><span style=&#34;text-decoration: line-through;&#34;><strong>if (ts.p.shrinkToFit === false) {initwidth += brd*cl;}</strong></span></div>
<p>The line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L1899" target="_blank">1899</a> should be changed:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7770' value='Select Code' data-codeid='sfcode7770' /></p>
<div class='sfcode' id='sfcode7770'>cw = Math.round(aw*this.width/(ts.p.tblwidth-<strong>brd*vc-gw</strong>));</div>
<p>The line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L1914" target="_blank">1914</a> should be also changed:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit6067' value='Select Code' data-codeid='sfcode6067' /></p>
<div class='sfcode' id='sfcode6067'>ts.p.tblwidth = initwidth+cr+<strong>vc*brd+gw</strong>;</div>
<p><strong><span style="text-decoration: underline;">Changes in the function ShowHideCol:</span></strong>&#160;Line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2789" target="_blank">2789</a>-2791:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit4539' value='Select Code' data-codeid='sfcode4539' /></p>
<div class='sfcode' id='sfcode4539'><strong>s</strong>howHideCol : function(colname,show) {<br />&#160;&#160; &#160;return this.each(function() {<br />&#160;&#160; &#160; &#160; &#160;var $t = this, fndh=false<strong>, brd=$.browser.safari? 0: $t.p.cellLayout, cw</strong>;</div>
<p>Line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2805" target="_blank">2805</a> soll be replaced to the follwoing lines</p>
<p><input type='button' class='sfcodeselect' name='sfselectit189' value='Select Code' data-codeid='sfcode189' /></p>
<div class='sfcode' id='sfcode189'><strong>cw = </strong><span style=&#34;font-weight: 800;&#34;>(</span><strong>this.widthOrg? this.widthOrg: parseInt(this.width,10)) + </strong><strong>brd</strong>;<br />if(show == &#34;none&#34;) { $t.p.tblwidth -= <strong>cw</strong>;} else {$t.p.tblwidth += <strong>cw</strong>;}&#160;</div>
<p>and the lines <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2811" target="_blank">2811</a>-2820 (the boby of the <strong>if(fndh===true)</strong>) to the following lines:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit1177' value='Select Code' data-codeid='sfcode1177' /></p>
<div class='sfcode' id='sfcode1177'><strong>if($t.p.shrinkToFit===true &#38;&#38; !isNaN($t.p.width) &#38;&#38; $t.grid.width!==$t.p.tblwidth) {</strong><br />&#160;&#160; &#160;<strong>$($t).jqGrid(&#34;setGridWidth&#34;,$t.p.tblwidth,true);</strong><br /><strong>} else {</strong><br />&#160;&#160; &#160;$(&#34;table:first&#34;,$t.grid.hDiv).width($t.p.tblwidth);<br />&#160;&#160; &#160;$(&#34;table:first&#34;,$t.grid.bDiv).width($t.p.tblwidth);<br />&#160;&#160; &#160;$t.grid.hDiv.scrollLeft = $t.grid.bDiv.scrollLeft;<br />&#160;&#160; &#160;if($t.p.footerrow) {<br />&#160;&#160; &#160; &#160; &#160;$(&#34;table:first&#34;,$t.grid.sDiv).width($t.p.tblwidth);<br />&#160;&#160; &#160; &#160; &#160;$t.grid.sDiv.scrollLeft = $t.grid.bDiv.scrollLeft;<br />&#160;&#160; &#160;}<br /><strong>}</strong></div>
<p>In the body of <strong>hideCol</strong> and <strong>showCol</strong> functions the function name <strong>ShowHideCol</strong> should be replaced to the <strong>showHideCol</strong>:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit9113' value='Select Code' data-codeid='sfcode9113' /></p>
<div class='sfcode' id='sfcode9113'>hideCol : function (colname) {<br />&#160;&#160; &#160;return this.each(function(){$(this).jqGrid(&#34;<strong>s</strong>howHideCol&#34;,colname,&#34;none&#34;);});<br />},<br />showCol : function(colname) {<br />&#160;&#160; &#160;return this.each(function(){$(this).jqGrid(&#34;<strong>s</strong>howHideCol&#34;,colname,&#34;&#34;);});<br />},&#160;</div>
<p><strong><span style="text-decoration: underline;">Changes in the function setGridWidth:</span></strong>&#160;Line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2880" target="_blank">2880</a>&#160;sholuld be changed to</p>
<p><input type='button' class='sfcodeselect' name='sfselectit4695' value='Select Code' data-codeid='sfcode4695' /></p>
<div class='sfcode' id='sfcode4695'>initwidth = 0, brd=$t.p.cellLayout, lvc, vc=0, hs=false, scw=$t.p.scrollOffset, aw, gw=0,<span style=&#34;text-decoration: line-through;&#34;><strong> tw=0,</strong></span></div>
<p>The lines <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2903" target="_blank">2903</a>-2906 to</p>
<p><input type='button' class='sfcodeselect' name='sfselectit3860' value='Select Code' data-codeid='sfcode3860' /></p>
<div class='sfcode' id='sfcode3860'><strong>cw = this.widthOrg? this.widthOrg: parseInt(this.width,10)</strong>;<br />initwidth += <strong>cw+brd</strong>;<br />if(this.fixed) {<br />&#160;&#160; &#160;<span style=&#34;text-decoration: line-through;&#34;><strong>tw += cw;</strong></span><br />&#160;&#160; &#160;gw += <strong>cw</strong>+brd;<br />} else {&#160;</div>
<p>The lines <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2926" target="_blank">2926</a> should be replaced to the next two lines:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit4539' value='Select Code' data-codeid='sfcode4539' /></p>
<div class='sfcode' id='sfcode4539'><strong>cw = this.widthOrg? this.widthOrg: parseInt(this.width,10);</strong><br />cw = Math.round(aw*cw/($t.p.tblwidth-<strong>brd*vc-gw</strong>));&#160;</div>
<p>and the line <a href="https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2946" target="_blank">2946</a>&#160;to</p>
<p><input type='button' class='sfcodeselect' name='sfselectit7596' value='Select Code' data-codeid='sfcode7596' /></p>
<div class='sfcode' id='sfcode7596'>$t.p.tblwidth = initwidth+cr+<strong>vc*brd+gw</strong>;</div>
<p>It&#39;s all. In many places the value <strong>vc*brd+gw</strong>&#160;will be used: the total width of border of all visible columns (<strong>vc*brd</strong>) plus the total width of fixed visible columns (<strong>gw</strong>). One can define one variable like <strong>fixedGridWidthPart</strong> for the value and use it instead of <strong>vc*brd+gw</strong>&#160;expression.</p>
<p>Moreover if one would make a little more changes in the code one could make it free from <strong>cellLayout</strong>&#160;parameter. The idea is to fill <strong>th</strong> elements with the <strong>width</strong> value from the <strong>colModel</strong>&#160;for all visable columns and place the corresponding DOM elements in <strong>grid.headers.el</strong>&#160;before calling of <strong>setColWidth</strong>. Then inside of <strong>setColWidth</strong>&#160;one could just use <a href="http://api.jquery.com/outerWidth/" target="_blank">jQuery.outerWidth</a>&#160;for calculating of the full grid width (totalWidth below) and fixedGridWidthPart:</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2009' value='Select Code' data-codeid='sfcode2009' /></p>
<div class='sfcode' id='sfcode2009'>var totalWidth=0, outerWidth, totalVariableWidth=0, fixedGridWidthPart=0, cm, th,<br />&#160;&#160; &#160;i=0, headers=mygrid[0].grid.headers, l=headers.length, colModel = ts.p.colModel;</p>
<p>for (;i&#60;l; i++) {<br />&#160;&#160; &#160;th = headers[i].el;<br />&#160;&#160; &#160;if (th.style.display !== &#34;none&#34;) {<br />&#160;&#160; &#160; &#160; &#160;outerWidth = $(th).outerWidth();<br />&#160;&#160; &#160; &#160; &#160;totalWidth += outerWidth;<br />&#160;&#160; &#160; &#160; &#160;fixedGridWidthPart += cm.fixed? outerWidth: outerWidth - cm.width; //? $(th).width()<br />&#160;&#160; &#160;}<br />}&#160;</p>
</div>
<p>I don&#39;t made the corresponding changes to make changes in small steps and test all carefully.</p>
<p>Additionally it would be nice to share the parts of code for width calculation and column shrinking between <strong>setGridWidth</strong> and <strong>setColWidth</strong> functions.</p>
</p>
<p>Best regards<br />Oleg</p>
]]></description>
        	        	<pubDate>Sun, 27 Mar 2011 12:53:40 +0300</pubDate>
        </item>
</channel>
</rss>