Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento admin grid sending data from Action to Controller

I'm trying to write a custom action to run off of an admin grid that I have built. Is it possible to send a value from a column in the grid to the controller via either get or post?

I've tried googling, but I cannot find a proper explanation for this anywhere. A link to an explanation of the column settings ('getter', 'type' etc.) would also be useful if this is available.

like image 455
Geoff Avatar asked Apr 08 '26 18:04

Geoff


1 Answers

Add this code to your Grid.php:

        $this->addColumn('action',
            array(
            'header'    =>  Mage::helper('yourmodulename')->__('Action'),
            'width'     => '100',
            'type'      => 'action',
            'getter'    => 'getId',
            'actions'   => array(
                    array(
                            'caption'   => Mage::helper('yourmodulename')->__('Edit'),
                            'url'       => array('base'=> '*/*/edit'),
                            'field'     => 'id'
                    )
            ),
            'filter'    => false,
            'sortable'  => false,
            'index'     => 'stores',
            'is_system' => true,
    ));

That will build an "Edit" URL with the Id of the selected row as part of the URL. It will look something like <frontname>/<controllername>/edit/id/<value> where value is returned by the getter getId().

The getter field will execute any of the standard Magento magic getters, ie any attribute is gettable. So you could have getName or getProductUrl or getIsLeftHanded if you wanted and your controller can parse the attribute.

The controller can then retrieve that passed value using Mage::app()->getRequest()->getParam('attributename');

In terms of documentation/tutorials, have a read of this article on the website of @AlanStorm as it might help.

HTH,
JD

like image 83
Jonathan Day Avatar answered Apr 11 '26 12:04

Jonathan Day



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!