M
M
Maybe_V2016-07-16 22:10:37
PHP
Maybe_V, 2016-07-16 22:10:37

How to create multiple bulk grid actions?

I need to implement multiple bulk actions in grid.
I implement one delete action like this:

protected function _prepareMassaction()
    {
        $this->setMassactionIdField('entity_id');
        $this->getMassactionBlock()->setFormFieldName('entity_id');

        $this->getMassactionBlock()->addItem('delete', array(
            'label' => $this->__('Delete'),
            'url' => $this->getUrl( '*/*/massDelete'),
        ));
  return $this;
    }

In the controller I process the array and everything works correctly.
But how to do multiple mass actions?
For example, if you do this:
protected function _prepareMassaction()
    {
        $this->setMassactionIdField('entity_id');
        $this->getMassactionBlock()->setFormFieldName('entity_id');

        $this->getMassactionBlock()->addItem('delete', array(
            'label' => $this->__('Delete'),
            'url' => $this->getUrl( '*/*/massDelete'),
        ));

        $this->getMassactionBlock()->addItem('submit', array(
            'label' => $this->__('Aprove'),
            'url' => $this->getUrl( '*/*/massAprove'),
        ));


        return $this;
    }

That turns out to be nonsense. will always be processed Delete.
How can this possibility be realized?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Batishchev, 2016-07-20
@prokopov-vi

You are on the right path, you are a little inattentive.
If you look closely, _prepareMassaction is purely for adding buttons, and not for processing
Other methods are already used for processing, depending on the specified method in getUrl, such as massDeleteAction(), massApproveAction()
It can also be processed not by the same controller, but by another one by changing * to specific module, controller and action method names

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question