Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonata Admin remove the batch column from list view

Symfony 2.3.25, SonataAdminBundle

If i remove the 'delete' route from my admin by

$collection->clearExcept(array('list'));

in configureRoutes I get no 'batch' column in List View, which is what I want.

But I need the 'delete' action.

When I configureRoutes:

$collection->clearExcept(array('list', 'delete'));

I get the 'batch' column back, which I do not want. I do not want any batch actions or batch columns or anything batch.

I do want a 'Delete' button per row in an Actions column, which I get.

How do I suppress the batch column in list view?

like image 814
David Soussan Avatar asked Mar 04 '15 12:03

David Soussan


2 Answers

You can remove or add batch actions by overriding the batchActions method. You just have to add your own batchActions method in your Admin class.

To remove the delete action you have to do this :

class Admin
{
    public function getBatchActions()
    {
        $actions = parent::getBatchActions();
        unset($actions['delete']);

        return $actions;
    }
}

The documentation of the default SonataAdmin batchActions method : https://github.com/sonata-project/SonataAdminBundle/blob/master/Admin/Admin.php#L1142

like image 142
HypeR Avatar answered Oct 05 '22 06:10

HypeR


Update for year 2016+. Now you can customize batch actions by using:

configureBatchActions method inside your Admin class.

 /**
  * Allows you to customize batch actions.
  *
  * @param array $actions List of actions
  *
  * @return array
  */
 protected function configureBatchActions($actions)
 {
     return $actions;
 }
like image 22
Arkadiusz 'flies' Rzadkowolski Avatar answered Oct 05 '22 05:10

Arkadiusz 'flies' Rzadkowolski