<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Agence de Développement Informatique du Nord &#187; sort</title>
	<atom:link href="http://blog.adin.pro/tag/sort/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</title>
		<link>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/</link>
		<comments>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/#comments</comments>
		<pubDate>Wed, 30 Apr 2014 07:42:04 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=381</guid>
		<description><![CDATA[<p>You can easily filter column in a magento grid (see my previous post) but customize a sort is a little bit more hand made. In this example in the order grid, I want to sort by increment_id, but this is &#8230; <a href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You can easily filter column in a magento grid (see my previous post) but customize a sort is a little bit more hand made.</p>
<p>In this example in the order grid, I want to sort by increment_id, but this is a text fields and I want to sort it by numeric.</p>
<p>default sort : 1, 10, 100, 2, 3 &#8230;<br />
numeric sort : 1, 2, 3, 10, 100 &#8230;</p>
<p>If you look the SQL request, you got this</p>
<pre class="brush: php; title: ; notranslate">
SELECT `main_table`.* FROM `sales_flat_order_grid` AS `main_table` ORDER BY increment_id DESC LIMIT 20
</pre>
<p>To tell MySQL to sort this text column by numeric, you can add &#8220;+ 0&#8243; to the ORDER BY clause, this will transform the text field into numeric field</p>
<pre class="brush: php; title: ; notranslate">
SELECT `main_table`.* FROM `sales_flat_order_grid` AS `main_table` ORDER BY increment_id + 0 DESC LIMIT 20
</pre>
<p>Now, how to tell Magento to add &#8220;+ 0&#8243; to this sort ?</p>
<p>Override your grid class and modify the &#8220;_setCollectionOrder($column)&#8221; function.</p>
<pre class="brush: php; title: ; notranslate">
class Adin_Sales_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
    protected function _setCollectionOrder($column)
    {
        $collection = $this-&gt;getCollection();
        if ($collection) {
            $columnIndex = $column-&gt;getFilterIndex() ? $column-&gt;getFilterIndex() : $column-&gt;getIndex();
            if($columnIndex == 'increment_id')
            {
                $columnIndex = 'increment_id + 0';
            }
            $collection-&gt;setOrder($columnIndex, strtoupper($column-&gt;getDir()));
        }
        return $this;
    }
}
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL custom sort</title>
		<link>http://blog.adin.pro/2013-06-13/mysql-custom-sort/</link>
		<comments>http://blog.adin.pro/2013-06-13/mysql-custom-sort/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 08:51:14 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=232</guid>
		<description><![CDATA[<p>You are requesting some product on your database and you need to sort results by fixed column values ? You can use the ORDER BY FIELD() clause.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-06-13/mysql-custom-sort/">MySQL custom sort</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are requesting some product on your database and you need to sort results by fixed column values ?<br />
You can use the ORDER BY FIELD() clause.</p>
<pre class="brush: php; title: ; notranslate">
SELECT * FROM product WHERE product_id IN (4, 2, 8, 9, 5) ORDER BY FIELD(product_id,4, 2, 8, 9, 5)
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-06-13/mysql-custom-sort/">MySQL custom sort</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-06-13/mysql-custom-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple fields to sort  a magento collection</title>
		<link>http://blog.adin.pro/2013-03-07/multiple-fields-to-sort-a-magento-collection/</link>
		<comments>http://blog.adin.pro/2013-03-07/multiple-fields-to-sort-a-magento-collection/#comments</comments>
		<pubDate>Thu, 07 Mar 2013 15:27:12 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[multiple]]></category>
		<category><![CDATA[order]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=135</guid>
		<description><![CDATA[<p>If you want to sort a collection on multiple field like that : You just have to have some setOrder() call on your collection like that : That&#8217;s all folk&#8230;</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-07/multiple-fields-to-sort-a-magento-collection/">Multiple fields to sort  a magento collection</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you want to sort a collection on multiple field like that :</p>
<pre class="brush: php; title: ; notranslate">
select * from toto order by field1 asc, field2 desc
</pre>
<p>You just have to have some setOrder() call on your collection like that :</p>
<pre class="brush: php; title: ; notranslate">
$myCollection-&gt;getCollection()
             -&gt;setOrder('field1', 'asc')
             -&gt;setOrder('field2', 'desc')
             ;
</pre>
<p>That&#8217;s all folk&#8230;</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-07/multiple-fields-to-sort-a-magento-collection/">Multiple fields to sort  a magento collection</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-03-07/multiple-fields-to-sort-a-magento-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
