<?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: sortGrid calls sortData with colname rather than a header index</title>
	<link>http://www.trirand.com/blog/?page_id=393/bugs/sortgrid-calls-sortdata-with-colname-rather-than-a-header-index</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/sortgrid-calls-sortdata-with-colname-rather-than-a-header-index/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>dgallop on sortGrid calls sortData with colname rather than a header index</title>
        	<link>http://www.trirand.com/blog/?page_id=393/bugs/sortgrid-calls-sortdata-with-colname-rather-than-a-header-index#p6105</link>
        	<category>Bugs</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/bugs/sortgrid-calls-sortdata-with-colname-rather-than-a-header-index#p6105</guid>
        	        	<description><![CDATA[<p>The sortGrid function in grid.custom.js takes a colname and if this column is sortable calls sortData as follows:</p>
<p>$t.sortData(colname, idx, reload);</p>
<p>However sortData requires an index (in the form jqgh_ + colname) to be able to re-apply the sort image and correctly set the sortname.</p>
<p>Here is a snippet form the sortData code that relies on the index having &#39;jqgh_&#39; as a prefix to the colname.</p>
<p>$("tr th div#jqgh_"+ls+" img",thd).remove();<br />$("tr th div#jqgh_"+ls,thd).parent().removeClass(ts.p.sortclass);<br />iId = index.replace(&#39;.&#39;,"\\\\.");<br />$("tr th div#"+iId,thd).append(imgs).parent().addClass(ts.p.sortclass);<br />ts.p.lastsort = idxcol;<br />index = index.substring(5);<br />ts.p.sortname = ts.p.colModel[idxcol].index &#124;&#124; index;<br />so = ts.p.sortorder;<br />if(onSortCol) {onSortCol(index,idxcol,so);}</p>
<p>&#160;You can see that the image is removed along with the class using an id of jqgh_ + a column name. However if the index passed into sortData does not have jqgh_ as a prefix (as it does when called from other parts of grid.base.js) the sorting does not work.</p>
<p>My fix to this has been to alter sortGrid function in grid.custom.js to the following:</p>
</p>
<p>sortGrid : function(colname,reload){<br />&#160;&#160;&#160; &#160;&#160;&#160; return this.each(function(){<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; var $t=this,idx=-1;<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; if ( !$t.grid ) { return;}<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; if ( !colname ) { colname = $t.p.sortname; }<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; for ( var i=0;i&#60;$t.p.colModel.length;i++ ) {<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; if ( $t.p.colModel[i].index == colname &#124;&#124; $t.p.colModel[i].name==colname ) {<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; idx = i;<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; break;<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; }<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; }<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; if ( idx!=-1 ){<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; var sort = $t.p.colModel[idx].sortable;<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; if ( typeof sort !== &#39;boolean&#39; ) { sort =&#160; true; }<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; if ( typeof reload !==&#39;boolean&#39; ) { reload = false; }<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; /* David Gallop 5/3/2009<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;* The colname expected by the sortData function<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;* in grid_base.js requires a prefix of jqgh_<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;* as it is used as an id to the grid header<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; if ( sort ) { $t.sortData(&#39;jqgh_&#39; + colname, idx, reload); }<br />&#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; }<br />&#160;&#160;&#160; &#160;&#160;&#160; });<br />&#160;&#160;&#160; },</p>
<p>Please could this fix be included in future releases.</p>
<p>best regards and keep up the good work, Dave.</p>
]]></description>
        	        	<pubDate>Thu, 16 Apr 2009 05:41:29 +0300</pubDate>
        </item>
</channel>
</rss>