Sonata Admin 从列表视图中删除批处理列

Sonata Admin remove the batch column from list view

Symfony 2.3.25,SonataAdminBundle

如果我通过

从我的管理员中删除 'delete' 路由
$collection->clearExcept(array('list'));

在 configureRoutes 中,列表视图中没有 'batch' 列,这正是我想要的。

但我需要 'delete' 操作。

当我配置路由时:

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

我取回 'batch' 列,这是我不想要的。我不想要任何批处理操作或批处理列或任何批处理。

我确实希望在“操作”列中每行有一个 'Delete' 按钮,我得到了。

如何在列表视图中隐藏批处理列?

您可以通过覆盖 batchActions 方法来删​​除或添加批处理操作。 您只需在 Admin class 中添加自己的 batchActions 方法。

要删除删除操作,您必须这样做:

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

        return $actions;
    }
}

默认 SonataAdmin batchActions 方法的文档:https://github.com/sonata-project/SonataAdminBundle/blob/master/Admin/Admin.php#L1142

2016 年以后更新。现在您可以使用以下方式自定义批处理操作:

configureBatchActions 管理中的方法 class.

 /**
  * Allows you to customize batch actions.
  *
  * @param array $actions List of actions
  *
  * @return array
  */
 protected function configureBatchActions($actions)
 {
     return $actions;
 }

您还可以使用以下内容:

/**
 * {@inheritdoc}
 */
public function configureBatchActions($actions)
{
    if (isset($actions['delete'])) {
        unset($actions['delete']);
    }

    return $actions;
}