Magento – Grid action column getter not getting the field

adminhtmlgridmagento-1

My action column 'getter' is not getting the field 'meter_id' that I need. (Magento 1.9) Here is my code:

    $link= $this->getUrl('*/*/edit', array(
        'id'        => $this->getRequest()->getParam('id'),
        'key'       => $this->getRequest()->getParam('key'),
        'action'    => 'delete'
    ));

    $this->addColumn('action_delete', array(
        'index'     => 'meter_id',
        'getter'    => 'getMeterId',
        'header'    => 'Action',
        'width'     => 15,
        'sortable'  => false,
        'filter'    => false,
        'type'      => 'action',
        'actions'   => array(
            array(
                'url'     => $link,
                'caption' => 'Delete',
                'field'   => 'meter_id'
            ),
        )
    ));

Results in this url when clicked:

http://127.0.0.1/... .../edit/id/1/key/82a03e3076236b17dc32c6eb2ea53601/action/delete/

I need the 'meter_id' field key in the url too and don't understand my error.

Best Answer

The problem was the getURL method does not work together with the getter and field. The getter works perfectly once getURL was removed and the link restructured as follows:

    $link = array(
        'base'      => '*/*/edit' .
        '/id/' . $this->getRequest()->getParam('id') .
        '/action/' . 'delete');

    $this->addColumn('action_delete', array(
        // 'index'      => 'meter_id',
        'getter'    => 'getMeterId',
        'header'    => 'Action',
        'width'     => 15,
        'sortable'  => false,
        'filter'    => false,
        'type'      => 'action',
        'actions'   => array(
            array(
                'url'     => $link,
                'caption' => 'Delete',
                'field'   => 'meter_id'
            ),
        )
    ));

resulting URL with desired query string:

http://127.0.0.1/magento/index.php/... .../edit/id/1/action/delete/meter_id/1/key/82a03e3076236b17dc32c6eb2ea53601/

I hope this helps you too!

Related Topic