0

How can I use in GridView delete selected object,in Yii 2 Framework such as following image:

enter image description here

<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
    'id',
    'name',
    'created_at:datetime',
    // ...
],

]) ?>

1 Answer 1

2

Add checkbox action column in gridView like

<?= GridView::widget([
   'dataProvider' => $dataProvider,
   'columns' => [
      [
        'class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($data) {
                return ['value' => $data->id];
            },
      ],
      'id',
      'name',
      'created_at:datetime',
      // ...
   ],
 ]) ?>

And Now Access the selected id in your controller like

class YourController extends Controller
{
  public function actionHear()
  {
    if(isset($_REQUEST['selection']))
    {
       ".........Your Code Hear.........."
     }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.