Yii2 uses GridView to implement buttons for selecting all data and deleting data in batches

不言
Release: 2023-04-01 11:40:01
Original
2252 people have browsed it

This article mainly introduces the example of using GridView to implement all data selection and batch deletion buttons in yii2. It has certain reference value. Those who are interested can learn more.

After sorting through the documents, I found an example of using GridView to implement all-data selection and batch deletion buttons. I sorted it out a bit and simplified it for sharing.

Let’s first look at the effect of implementation

The key code is as follows:

   $dataProvider,
   'showFooter' => true, //设置显示最下面的footer
    'id' => 'grid',
    'columns' => [
     [
      'class'=>CheckboxColumn::className(),
      'name'=>'id',
      'headerOptions' => ['width'=>'30'],
      'footer' => '',
      'footerOptions' => ['colspan' => 5],
     ],
     ['attribute' => 'id', 'footerOptions' => ['class'=>'hide']], //其他列每个都要增加footerOptions项,设置class为hide,到达隐藏效果;
     ['attribute' => 'username', 'footerOptions' => ['class'=>'hide']],
     [
      'attribute' => 'status',
      'value' => function($model){
       if ($model->status == Admin::STATUS_ACTIVE){
        return '启用';
       }
       return '禁用';
      },
      'footerOptions' => ['class'=>'hide']
     ],
     ['class' => 'yii\grid\ActionColumn', 'header' => '管理操作', 'footerOptions' => ['class'=>'hide']],
    ],
   'layout' => "{items}\n{pager}"
  ]); ?>
Copy after login

Getting the final selected data:

var ids = $("#grid").yiiGridView("getSelectedRows");
Copy after login

After getting the data, you can ajax submit it to the desired controller

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

yii2 implements paging and paging with search functions

About how to write search paging jQuery in the YII framework

The above is the detailed content of Yii2 uses GridView to implement buttons for selecting all data and deleting data in batches. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!