<?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: custom multi-column sorting in a jqgrid on json data</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data</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/custom-multi-column-sorting-in-a-jqgrid-on-json-data/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>ChristopheL on custom multi-column sorting in a jqgrid on json data</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25227</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25227</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Thanks for your suggestion.</p>
<p>If I understand correctly, you mean that the index position of the column will be used to decide if the sort needs to be reset or not, assuming that colum on the left are "more important" than the one on the right.</p>
<p>In my case a sort on the last column on the right then on the first column on the left will be an interesting sort for the user so I can&#39;t do that.</p>
<p>Regards</p>
]]></description>
        	        	<pubDate>Wed, 23 Nov 2011 14:43:12 +0200</pubDate>
        </item>
        <item>
        	<title>tony on custom multi-column sorting in a jqgrid on json data</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25218</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25218</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Another possible solution is to analyze the sort.</p>
<p>This can be something like this.</p>
</p>
<p>The user click a column to sort.</p>
<p>The user click another column to sort - if this column is with higher index (from colModel - NOT index property) the sort is added if not the sort is reset automatically and the begin to sort from this index.</p>
<p>I hope you got the idea.</p>
</p>
<p>Kind Regads</p>
]]></description>
        	        	<pubDate>Wed, 23 Nov 2011 08:28:52 +0200</pubDate>
        </item>
        <item>
        	<title>ChristopheL on custom multi-column sorting in a jqgrid on json data</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25215</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25215</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>For the moment, I click on a link which points on the same page and so reload the page which causes the javascript global variable to be reset.</p>
<p>But I have seen there is a concept of toolbar in jqGrid ( I guess it is the icons at the bottom left of the grid), so I will try to add an icon there which would have as purpose to clean the global variables.</p>
<p>Regards,</p>
<p>Christophe</p>
]]></description>
        	        	<pubDate>Wed, 23 Nov 2011 08:16:00 +0200</pubDate>
        </item>
        <item>
        	<title>tony on custom multi-column sorting in a jqgrid on json data</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25214</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25214</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Good beginning.</p>
<p>How we can destroy the sort in order to begin new one?</p>
<p>Regards</p>
]]></description>
        	        	<pubDate>Wed, 23 Nov 2011 08:06:30 +0200</pubDate>
        </item>
        <item>
        	<title>ChristopheL on custom multi-column sorting in a jqgrid on json data</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25211</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/custom-multi-column-sorting-in-a-jqgrid-on-json-data#p25211</guid>
        	        	<description><![CDATA[<p>Hello,</p>
<p>Since it looks like jqGrid is not supporting multi-column sorting natively, I have tried to implement a custom sort which is acting like a multi-column sorting on my json data.</p>
<p>Since I&#39;m new to jqGrid, I post it here, so anyone can feel free to comment and give feedback about this way to do it.</p>
<p>Anyway, it&#39;s far from perfect since the sort icon are not synchronized with the actual sorting ( only one arrow in one column is &#39;selected&#39; ), but at least it gives a way to sort on more than one column.</p>
<p>Thanks in advance for your feedback on the below code.</p>
<p>Best regards,</p>
<p>Christophe</p>
</p>
<p>Step 1)</p>
<p>declaring two global variables which will contain the information about the sorting:</p>
</p>
<p>// this array contains the ordered list of index name in which the sorting has to be applied</p>
<p>var vmOverviewTableSortingOrderedList = new Array();</p>
<p>// this associative array contains the association index name =&#62; order</p>
<p>var vmOverviewTableSortingHash = new Array();</p>
</p>
<p>Step 2)</p>
<p>declaring a global method which will update the two global variables on each sorting request from the user</p>
</p>
<p>function updateVmOverviewTableSorting(propertyName, order)<br />{</p>
<p>&#160;&#160;&#160; // remove the index name from the ordered list, whatever its position, it will be removed<br />&#160;&#160;&#160; vmOverviewTableSortingOrderedList <br />&#160;&#160; &#160;&#160;&#160; &#160;= jQuery.grep(vmOverviewTableSortingOrderedList, function(value) {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;return value != propertyName;<br />&#160;&#160; &#160;&#160;&#160; &#160;});</p>
<p>&#160;&#160;&#160; // add the index name as first element in the ordered list<br />&#160;&#160; &#160;vmOverviewTableSortingOrderedList.unshift(propertyName);</p>
<p>&#160; &#160; // add or update the association index name =&#62; order &#160;&#160; <br />&#160;&#160; &#160;vmOverviewTableSortingHash[propertyName] = order;<br />}</p>
</p>
<p>Step 3)</p>
<p>Defines two url parameters which will be used to send the sorting information to the server:</p>
<p>- &#39;sortnames&#39; which is an index name comma-separated list</p>
<p>- &#39;sortorders&#39; for the order list</p>
<p>Below is the initial url defining an initial sorting on the index name &#39;name&#39; in ascending order &#39;asc&#39;</p>
<p>jQuery("#vmOverviewTable").jqGrid({<br />&#160;&#160; &#160;url : &#39;vmOverviews?sortnames=name&#38;sortorders=asc&#39;,<br />&#160;&#160; &#160;datatype : "json",</p>
</p>
<p>Step 4)</p>
<p>Defining a onSortCol function which updates the global variables and the url:</p>
<p>&#160;&#160;&#160; onSortCol: function (index, columnIndex, sortOrder) {<br />&#160;&#160; &#160;&#160;&#160;&#160; // update the two global variables<br />&#160;&#160; &#160;&#160;&#160; &#160;updateVmOverviewTableSorting(index, sortOrder);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // creates the two comma-separated list (one for the index name, the other for the order)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // from the data in the two global variables<br />&#160;&#160; &#160;&#160;&#160;&#160; var sortPropertyNames = &#39;&#39;;<br />&#160;&#160; &#160;&#160;&#160; &#160;var sortOrders = &#39;&#39;;</p>
<p>&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;$.each(vmOverviewTableSortingOrderedList, function(index, value) {<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;if (sortPropertyNames.length != 0)<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;{<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;sortPropertyNames += &#39;,&#39;;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;sortOrders += &#39;,&#39;;<br />&#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;sortPropertyNames += value;<br />&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;sortOrders += vmOverviewTableSortingHash[value];<br />&#160;&#160; &#160;&#160;&#160;&#160; });</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // change the url with the two url parameters changed with the new comma-separated list<br />&#160;&#160; &#160;&#160;&#160; &#160;var url = &#39;vmOverviews?sortnames=&#39;+sortPropertyNames+&#39;&#38;sortorders=&#39;+sortOrders;<br />&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;$("#vmOverviewTable").jqGrid(&#39;setGridParam&#39;,{&#39;url&#39;:url});</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // we DON&#39;T return "stop" here, so the default sorting process code is executed (such calling the url in ajax)<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return &#39;&#39;;<br />&#160;&#160;&#160; }</p>
</p>
<p>Step 5)</p>
<p>I don&#39;t provide the code here, but the final step is to handle the parameters in the server-side controller in order to implement the sorting on the server side.</p>
<p>For example, my Symfony2 action is starting like this:</p>
<p>&#160;&#160;&#160;&#160; /**<br />&#160;&#160;&#160;&#160; * @Route("/vmOverviews", name="_paas_vmOverviews", defaults={"_format"="json"})<br />&#160;&#160;&#160;&#160; * @Template()<br />&#160;&#160;&#160;&#160; */<br />&#160;&#160; &#160;public function vmOverviewsAction()<br />&#160;&#160; &#160;{<br />&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;$request = $this-&#62;getRequest();<br />&#160;&#160; &#160;&#160;&#160; &#160;<br />&#160;&#160; &#160;&#160;&#160; &#160;$sortnames = $request-&#62;query-&#62;get(&#39;<strong>sortnames</strong>&#39;); <br />&#160;&#160; &#160;&#160;&#160; &#160;$sortorders = $request-&#62;query-&#62;get(&#39;<strong>sortorders</strong>&#39;);</p>
]]></description>
        	        	<pubDate>Tue, 22 Nov 2011 21:40:32 +0200</pubDate>
        </item>
</channel>
</rss>