1. Add custom class or id to pjax container
Either add a class or id to your pjax container with a GridView, so that you are not dependent on automatically generated classes and identifiers (or if you have several GridView widgets on the same page).
kartik\grid\CheckboxColumn is just an extended version of yii \ grid \ CheckboxColumn .
kartik\grid\View has containerOptions , you can specify a class here, it seems that id automatically generated and cannot be changed using this property.
'containerOptions' => ['class' => 'hotel-pjax-container'],
An example of the generated output:
<div class="hotel-pjax-container table-responsive" id="w0-container">...</div>
yii\grid\View\ has options , here you can specify id . The identifier of the result container will be the prefix of the passed value, for example:
'options' => ['id' => 'hotel-pjax'],
Generated Output:
<div class="table-responsive" id="hotel-pjax-container">...</div>
The class is ignored in this case.
I recommend specifying an identifier.
2. Create or modify an action for deletion in the controller
By default, the delete action generated by gii is redirected, so we can create another action for multiple deletion (or you can handle it in one, it is up to you).
public function actionDeleteMultiple() { $pk = Yii::$app->request->post('pk'); // Array or selected records primary keys // Preventing extra unnecessary query if (!$pk) { return; } return Hotel::deleteAll(['hotel_id' => $pk]); }
Please note that if you did not specify any condition in deleteAll() , all entries in the table will be deleted! Be precise with that.
You can also specify an action in VerbFilter as follows:
use yii\filters\VerbFilter; public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], 'delete-multiple' => ['post'], ], ], ]; }
3. Write javascript to link everything together
You can get the primary keys of selected rows as follows:
$('#hotel-pjax-container').yiiGridView('getSelectedRows');
Add this javascript (e.g. to a button):
$.post( "delete-multiple", { pk : $('#hotel-pjax-container').yiiGridView('getSelectedRows') }, function () { $.pjax.reload({container:'#hotel-pjax-container'}); } );
For more information on updating GridView with pjax, see issue . Perhaps try this: $('#hotel-pjax-container').yiiGridView('applyFilter'); as an alternative; Include js using assets, or simply using registerJs() ;