Magento Adminhtml – Setting a Custom massAction Index to Your Grid

| March 31, 2016 | 0 Comments

If you ever run into a situation where you need to set a massAction column to use a value other than the grid’s index value, all it takes is two lines In your _prepareMassAction() function.

// setting the mass action value to our specified column value
$this->setMassactionIdFieldOnlyIndexValue(true);
$this->setMassactionIdField('product_id'); // column index

The complete function in your Company_Extension_Block_Adminhtml_Custom_Grid should look something like this

protected function _prepareMassaction() {
    $this->getMassactionBlock()->setFormFieldName('products'); // checkbox field name
 
    // setting the mass action value to our specified column value
    $this->setMassactionIdFieldOnlyIndexValue(true);
    $this->setMassactionIdField('product_id'); // column index
 
    $this->getMassactionBlock()->addItem('update', array(
         'label'    => Mage::helper('labels')->__('Mark in Stock'),
         'url'      => $this->getUrl('*/*/massStock'),
         'confirm'  => Mage::helper('labels')->__('Are you sure you want to update these product(s)?')
    ));
 
    return $this;
}

Category: PHP

About the Author (Author Profile)

Leave a Reply

You must be logged in to post a comment.