Admin grid massaction checkboxes default checked & option set to action I want
-
12-12-2019 - |
Question
Just like the question keep the checkboxes of mass action checked for some items, by default, but I simply want all checkboxes checked by default, plus a default mass-action is selected on first landing.
E.g. a landing grid page:
Should I just use JS to select them? Or need to go through all backend PHP for it?!?
Solution
You can have a selected mass action by default by defining it in your grid block like this:
$this->getMassactionBlock()->addItem('mass_action_code_here', array(
'label' => Mage::helper('helper_name_here')->__('Label here'),
'url' => $this->getUrl('*/*/urlHere'),
'selected' => true, //This is what you need
));
And you can select all the checkboxes by default like this.
Add a method called _prepareMassactionColumn
in your grid block with this content.
protected function _prepareMassactionColumn()
{
parent::_prepareMassactionColumn();
$ids = Mage::getModel('your_model/alias_here')->getCollection()->getAllIds();
$this->getColumn('massaction')->setValues($ids);
return $this;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange