I have created a custom module and need to add checkboxes to the grid and be able to delete multiple values with a mass action. Tried to use number of different articles but nothing worked. Can anyone help me to do this or maybe you know a good working article about this?
Here is the code in controller file:
public function massDeleteAction() {
$requestIds = $this->getRequest()->getParam('id');
if(!is_array($requestIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select reqeust(s)'));
} else {
try {
foreach ($requestIds as $requestId) {
$RequestData = Mage::getModel('cpstest_productcomment/cps_collection')->load($requestId);
$RequestData->delete();
}
Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('adminhtml')->__(
'Total of %d record(s) were successfully deleted', count($requestIds)
)
);
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
$this->_redirect('*/*/');
}
And the code in Grid.php
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('id');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('adminhtml')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('adminhtml')->__('Are you sure?')
));
return $this;
}