<?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; grid</title>
	<atom:link href="http://blog.adin.pro/tag/grid/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 &#8211; add a new action in grid</title>
		<link>http://blog.adin.pro/2014-08-20/magento-add-a-new-action-in-grid/</link>
		<comments>http://blog.adin.pro/2014-08-20/magento-add-a-new-action-in-grid/#comments</comments>
		<pubDate>Wed, 20 Aug 2014 08:27:13 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[Override]]></category>
		<category><![CDATA[_preparecolumns]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=398</guid>
		<description><![CDATA[<p>Here, how to add new action in grid like &#8216;Edit&#8217; link at admin grid. On this example, we will add a &#8220;schedule&#8221; action in product admin grid. We will overrite this class /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php. Declare the rewrite class on the /app/code/local/Adin/Catalog/etc/config.xml &#8230; <a href="http://blog.adin.pro/2014-08-20/magento-add-a-new-action-in-grid/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-08-20/magento-add-a-new-action-in-grid/">Magento &#8211; add a new action in grid</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>Here, how to add new action in grid like &#8216;Edit&#8217; link at admin grid.<br />
On this example, we will add a &#8220;schedule&#8221; action in product admin grid.</p>
<p>We will overrite this class /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php.</p>
<p>Declare the rewrite class on the /app/code/local/Adin/Catalog/etc/config.xml<br />
and add</p>
<pre class="brush: xml; title: ; notranslate">
&lt;global&gt;
      &lt;blocks&gt;
            &lt;adminhtml&gt;
                &lt;rewrite&gt;
                    &lt;catalog_product_grid&gt;Adin_Catalog_Block_Adminhtml_Catalog_Product_Grid&lt;/catalog_product_grid&gt;
                &lt;/rewrite&gt;
            &lt;/adminhtml&gt;
        &lt;/blocks&gt;
&lt;/global&gt;
</pre>
<p>Then create your rewritted class /app/code/local/Adin/Catalog/Block/Adminhtml/Catalog/Product/Grid.php.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class Adin_Catalog_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid {
}
?&gt;
</pre>
<p>Now, rewrite the _prepareColumns() function, find the &#8216;action&#8217; column an add an entry in the actions array</p>
<pre class="brush: php; title: ; notranslate">
  $this-&gt;addColumn('action',
            array(
                'header'    =&gt; Mage::helper('catalog')-&gt;__('Action'),
                'width'     =&gt; '50px',
                'type'      =&gt; 'action',
                'getter'     =&gt; 'getId',
                'actions'   =&gt; array(
                    array(
                        'caption' =&gt; Mage::helper('catalog')-&gt;__('Edit'),
                        'url'     =&gt; array(
                            'base'=&gt;'*/*/edit',
                            'params'=&gt;array('store'=&gt;$this-&gt;getRequest()-&gt;getParam('store'))
                        ),
                        'field'   =&gt; 'id'
                    ),
                    array(
                        'caption' =&gt; Mage::helper('catalog')-&gt;__('Schedule'),
                        'url'     =&gt; array(
                            'base'=&gt;'*/*/schedule',
                            'params'=&gt;array('store'=&gt;$this-&gt;getRequest()-&gt;getParam('store'))
                        ),
                        'field'   =&gt; 'id'
                    ),
                ),
                'filter'    =&gt; false,
                'sortable'  =&gt; false,
                'index'     =&gt; 'stores',
            ));
</pre>
<p>In our example, we just add this part</p>
<pre class="brush: php; title: ; notranslate">
array(
                        'caption' =&gt; Mage::helper('catalog')-&gt;__('Schedule'),
                        'url'     =&gt; array(
                            'base'=&gt;'*/*/schedule',
                            'params'=&gt;array('store'=&gt;$this-&gt;getRequest()-&gt;getParam('store'))
                        ),
                        'field'   =&gt; 'id'
                    ),
</pre>
<p>One last thing, at the end of the _prepareColumns function, change</p>
<pre class="brush: php; title: ; notranslate">
return parent::_prepareColumns();
</pre>
<p>by</p>
<pre class="brush: php; title: ; notranslate">
return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-08-20/magento-add-a-new-action-in-grid/">Magento &#8211; add a new action in grid</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-08-20/magento-add-a-new-action-in-grid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Magento custom filter on grid</title>
		<link>http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/</link>
		<comments>http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/#comments</comments>
		<pubDate>Fri, 25 Apr 2014 14:09:44 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[magento]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=378</guid>
		<description><![CDATA[<p>Sometimes, you need a special column on your grid from another table or with some calculation. It works well, column is displayed but filter doesn&#8217;t work. Here a small example how to customize your filter : On your grid class &#8230; <a href="http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/">Magento custom filter on grid</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>Sometimes, you need a special column on your grid from another table or with some calculation.<br />
It works well, column is displayed but filter doesn&#8217;t work.<br />
Here a small example how to customize your filter :</p>
<p>On your grid class (Adin_Sponsorship_Block_Adminhtml_Sponsorship_Grid.class.php), override your _prepareColumns() function</p>
<pre class="brush: php; title: ; notranslate">
protected function _prepareColumns()
{
        $this-&gt;addColumn('sponsor_email', array(
                'header'    =&gt; Mage::helper('evian_customer')-&gt;__('Sponsor Email'),
                'index'     =&gt; 'sponsor_email',
                'align'     =&gt; 'center',
                'filter_condition_callback' =&gt; array($this, '_filterSponsortEmail'),
            )
        );
}
</pre>
<p>The &#8216;filter_condition_callback&#8217; option indicates to use as filter a specific method, on the current class ($this) the method _filterSponsortEmail().</p>
<p>So next step, create this method.</p>
<pre class="brush: php; title: ; notranslate">
    protected function _filterSponsortEmail($collection, $column)
    {
        if (!$value = trim($column-&gt;getFilter()-&gt;getValue())) {
            return;
        }
        $this-&gt;getCollection()-&gt;addFieldToFilter('customer.email', array('like' =&gt; '%'.$value.'%'));
    }
</pre>
<p>Yes, this is this simple.</p>
<p>If you use a datetime column, it&#8217;s just a bit more complicated, see below</p>
<pre class="brush: php; title: ; notranslate">
        $this-&gt;addColumn('created_at', array(
            'header'    =&gt; Mage::helper('evian_customer')-&gt;__('Date of sponsorship'),
            'index'     =&gt; 'created_at',
            'align'     =&gt; 'center',
            'type' =&gt; 'datetime',
            'filter_condition_callback' =&gt; array($this, '_filterDate'),
            )
        );
</pre>
<p>and the filter method</p>
<pre class="brush: php; title: ; notranslate">
    protected function _filterDate($collection, $column)
    {
        $filters = $column-&gt;getFilter()-&gt;getValue();

            $from = $filters['from'];
            $to = $filters['to'];


       $this-&gt;getCollection()-&gt;addFieldToFilter('main_table.created_at', array('gteq' =&gt; $from-&gt;toString('yyyy-MM-dd')));
        $this-&gt;getCollection()-&gt;addFieldToFilter('main_table.created_at', array('lteq' =&gt; $to-&gt;toString('yyyy-MM-dd')));
    }
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-25/magento-custom-filter-on-grid/">Magento custom filter on grid</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-25/magento-custom-filter-on-grid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
