<?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: Sorting vs row selection</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/sorting-vs-row-selection</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/help/sorting-vs-row-selection/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>MaaKut on Sorting vs row selection</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/sorting-vs-row-selection#p27006</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/sorting-vs-row-selection#p27006</guid>
        	        	<description><![CDATA[<p>I&#39;m trying to create a grid with sortable columns using jqGrid 4.4.0. The code is below</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit2215' value='Select Code' data-codeid='sfcode2215' /></p>
<div class='sfcode' id='sfcode2215'>$(function() {<br /> var selectedRowId = null; </p>
<p> $(&#39;#grid2&#39;).jqGrid({<br />&#160; localReader: { id: &#39;_id&#39; },<br />&#160; datatype: &#39;local&#39;,<br />&#160; height: &#39;auto&#39;,<br />&#160; colNames: [&#39;id&#39;, &#39;Full Name&#39;, &#39;Short Name&#39;],<br />&#160; autowidth: true,<br />&#160; shrinkToFit: true,<br />&#160; multiselect: false,<br />&#160; deselectAfterSort: false,<br />&#160; colModel: [<br />&#160; &#160; { name: &#39;_id&#39;, index: &#39;_id&#39;, hidden: true, key: true },<br />&#160; &#160; { name: &#39;name&#39;, index: &#39;name&#39;, width: 600, sortable: true },<br />&#160; &#160; { name: &#39;shortName&#39;, index: &#39;shortName&#39;, width: 600, sortable: false }<br />&#160; ],<br />&#160; data: [<br />&#160; &#160; { _id: 1, name: &#39;Institution&#39;, shortName: &#39;I.1&#39; },<br />&#160; &#160; { _id: 2, name: &#39;Institution 1.1&#39;, shortName: &#39;I.1.1&#39; },<br />&#160; &#160; { _id: 3, name: &#39;One more institution 1.2&#39;, shortName: &#39;I.1.2&#39; },					&#160;<br />&#160; &#160; { _id: 4, name: &#39;Institution 1.2.1&#39;, shortName: &#39;I.1.2.1&#39; },<br />&#160; &#160; { _id: 6, name: &#39;Institution deep down&#39;, shortName: &#39;I.1.2.1&#39; },<br />&#160; &#160; { _id: 5, name: &#39;A long long institution name&#39;, shortName: &#39;I.2&#39; }<br />&#160; ],<br />&#160; onSelectRow: function(rowid, status) {<br />&#160; &#160; selectedRowId = rowid;<br /> &#160; },<br />&#160; onSortCol: function(index, iCol, sortorder) {<br />&#160; &#160; if (selectedRowId) {<br />&#160; &#160; &#160; &#160;setTimeout(function() {<br />&#160; &#160; &#160; &#160; &#160; $(&#39;#grid2&#39;).jqGrid(&#39;resetSelection&#39;);<br />&#160; &#160; &#160; &#160; &#160; $(&#39;#grid2&#39;).jqGrid(&#39;setSelection&#39;, selectedRowId, false);<br />&#160; &#160; &#160; &#160;}, 300);<br />&#160; &#160; }<br />&#160; }<br /> });<br />});</p>
</div>
<p>&#160;The problem is that when the grid is sorted, the selected row is not highlighted any more. At the same time the grid itself still thinks the row is still selected (onSelectRow fires with status &#39;false&#39; if I click on it), and this is very conufusing for the user.</p>
<p>I&#39;ve implemented a workaround to remember the selection and restore it programmatically after sort, however it relies on setTimeout (without it setSelection has no effect) which makes it pretty much ugly. &#160;Is there a better way to support both sorting and selection?</p>
]]></description>
        	        	<pubDate>Tue, 24 Jul 2012 16:33:33 +0300</pubDate>
        </item>
</channel>
</rss>