Magento Admin Grid: how to change number of rows

Magento Admin Grid: how to change number of rows

We had a request from our client, that we change default number of items in Magento admin grid. Now, this is very simple, when we know how to change it. Below you can see an example which uses magento observer model and event hocking “core_block_abstract_prepare_layout_before”.

First of all, make backup copies of your files.

Step 1.
This is example of event hocking, put it in config.xml

<adminhtml>
        <events>            
            <core_block_abstract_prepare_layout_before>
    			<observers>
                    <reward>
                        <class>grid/observer</class>
                        <method>applyLimitToGrid</method>
                    </reward>
                </observers>
    		</core_block_abstract_prepare_layout_before>
 
        </events>
    </adminhtml>

Step 2.
Create model class observer.php

class Inchoo_Grid_Model_Observer
{
 
    public function applyLimitToGrid(Varien_Event_Observer $observer)
    {
    	$block = $observer->getEvent()->getBlock();
    	if(($block instanceof Mage_Adminhtml_Block_Widget_Grid) &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp; !($block  instanceof Mage_Adminhtml_Block_Dashboard_Grid))
    	$block->setDefaultLimit(200);
 
    }
 
 
}

It would be good that you make your own module and all put in it. I hope that you know how to make magento module.

You made it all the way down here so you must have enjoyed this post! You may also like:

Magento Grid Serializer for Ajax Grids Damir Korpar
Damir Korpar, | 10

Magento Grid Serializer for Ajax Grids

Show product thumbnail in grids Petar Sambolek
Petar Sambolek, | 14

Show product thumbnail in grids

Filter order grid by multiple ID’s Petar Sambolek
Petar Sambolek, | 14

Filter order grid by multiple ID’s

6 comments

  1. Hi,
    I am facing problem in admin shopping cart price rule grid. when i click “manage coupon codes” tap just need to change the grid limit like 20 to 30.

    Please do the needful

    Thanks,
    Sankar V

  2. It is enough only set default limit in _counstruct():
    class … extends Mage_Adminhtml_Block_Widget_Grid
    {
    public function __construct()
    {
    parent::__construct();
    $this->setId(‘related_product_grid’);
    $this->setDefaultSort(‘entity_id’);
    $this->setUseAjax(true);

    $this->setDefaultSort(‘sku’);
    $this->setDefaultDir(‘asc’);
    $this->setSaveParametersInSession(true);
    $this->setDefaultLimit(200);

    }

  3. Can you please provide more info about this?
    How can i set it using new module.I am already aware with how to create module in local folder.I cant set default limit as 200 by creating module.

  4. Sweet. I was getting bugged myself looking at a lists that default to 20 records. Thanks for the code snippets. Worked great.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.