1) Přidat složku /components v proekt a vytvořit soubor /components/MyCheckboxColumn.php
namespace app\components;
use yii\grid\CheckboxColumn;
use yii\helpers\Html;
class MyCheckboxColumn extends CheckboxColumn
{
public $filter = "";
protected function renderFilterCellContent()
{
return $this->filter;
}
}
2) LogController.php
public function actionBulkDelete()
{
$selection = (array)Yii::$app->request->post('selection');
foreach($selection as $id)
{
$this->findModel($id)->delete();
}
return $this->redirect(['index']);
}
3) index.php
<?php Pjax::begin(); ?>
<?=Html::beginForm([Yii::$app->controller->id . '/bulk-delete'], 'post');?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'id',
...
[
'class' => 'app\components\MyCheckboxColumn',
'headerOptions' => ['style'=>'text-align:center'],
'filterOptions' => ['style'=>'text-align:center'],
'filter' => Html::submitButton('<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>',['data'=>['confirm'=>'Opravdu smazat?']]),
'contentOptions' => ['style' => 'min-width: 5%; text-align: center;'],
],
],
]); ?>
<?= Html::endForm();?>
<?php Pjax::end(); ?>