Hi all I am able to create a admin grid for my custom module. In this grid I also provide the mass update functionality, and everything is working fine, thanks to some good tutorials on the internet.
The thing is when I use ->setStatus($this->getRequest()->getParam('status'))
to set the status for my grid, it is not working, I don't know why ?
so I do it like this ->setStatus('Active')
or ->setStatus('Inactive')
to change the status for the table values.
I am a new in magento so maybe I didn't understand it properly.
Can anyone tell me why it is not working.
Here is my function in my Grid.php
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('id');
$this->getMassactionBlock()->addItem('active', array(
'label'=> 'Active',
'url' => $this->getUrl('*/*/massActive', array('' => ''))
));
$this->getMassactionBlock()->addItem('inactive', array(
'label'=> 'Inactive',
'url' => $this->getUrl('*/*/massInactive', array('' => ''))
));
$this->getMassactionBlock()->addItem('delete', array(
'label'=> 'Delete',
'url' => $this->getUrl('*/*/massDelete', array('' => '')),
'confirm' => 'Are you sure?'
));
return $this;
}
and here is my controller function.
public function massActiveAction()
{
$catIds = $this->getRequest()->getParam('id');
if (!is_array($catIds)) {
Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
} else {
try {
foreach ($catIds as $catId) {
Mage::getSingleton('blog/blog')
->load($catId)
->setStatus('Active')
->setIsMassupdate(true)
->save();
}
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) were successfully updated', count($catIds))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}
Best Answer
Grid.php
Controller.php