yii2使用GridView實(shí)現(xiàn)數(shù)據(jù)全選及批量刪除按鈕示例
整理文檔,發(fā)現(xiàn)一個(gè)用GridView實(shí)現(xiàn)數(shù)據(jù)全選及批量刪除按鈕示例,稍微整理精簡一下做下分享。
先來看實(shí)現(xiàn)的效果

關(guān)鍵代碼如下:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'showFooter' => true, //設(shè)置顯示最下面的footer
'id' => 'grid',
'columns' => [
[
'class'=>CheckboxColumn::className(),
'name'=>'id',
'headerOptions' => ['width'=>'30'],
'footer' => '<button href="#" rel="external nofollow" class="btn btn-default btn-xs btn-delete" url="'. Url::toRoute('admin/delete') .'">刪除</button>',
'footerOptions' => ['colspan' => 5],
],
['attribute' => 'id', 'footerOptions' => ['class'=>'hide']], //其他列每個(gè)都要增加footerOptions項(xiàng),設(shè)置class為hide,到達(dá)隱藏效果;
['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}"
]); ?>
最后已選數(shù)據(jù)的獲?。?/p>
var ids = $("#grid").yiiGridView("getSelectedRows");
獲取數(shù)據(jù)后就可以ajax提交到想要的controller
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Yii中CArrayDataProvider和CActiveDataProvider區(qū)別實(shí)例分析
- 淺析Yii2中GridView常見操作
- yii2.0之GridView自定義按鈕和鏈接用法
- Yii2 GridView實(shí)現(xiàn)列表頁直接修改數(shù)據(jù)的方法
- 淺析Yii2 gridview實(shí)現(xiàn)批量刪除教程
- 淺析Yii2 GridView實(shí)現(xiàn)下拉搜索教程
- 淺析Yii2 GridView 日期格式化并實(shí)現(xiàn)日期可搜索教程
- yii2中結(jié)合gridview如何使用modal彈窗實(shí)例代碼詳解
- yii2使用gridView實(shí)現(xiàn)下拉列表篩選數(shù)據(jù)
- Yii2.0小部件GridView(兩表聯(lián)查/搜索/分頁)功能的實(shí)現(xiàn)代碼
- yii2-GridView在開發(fā)中常用的功能及技巧總結(jié)
- YII2框架中ActiveDataProvider與GridView的配合使用操作示例
相關(guān)文章
php實(shí)現(xiàn)簡單的權(quán)限管理的示例代碼
本篇文章主要介紹了php實(shí)現(xiàn)簡單的權(quán)限管理的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
PHP?ceil()函數(shù)浮點(diǎn)數(shù)向上取整實(shí)現(xiàn)示例
這篇文章主要為大家介紹了PHP?ceil()函數(shù)實(shí)現(xiàn)浮點(diǎn)數(shù)向上取整示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01
PHP調(diào)用.NET的WebService 簡單實(shí)例
這篇文章主要介紹了使用PHP調(diào)用.NET的WebService的一個(gè)簡單實(shí)例,十分的簡單,有需要的小伙伴可以自己擴(kuò)展下,如有疑問請留言。2015-03-03
windows7配置Nginx+php+mysql的詳細(xì)教程
這篇文章主要介紹了windows7配置Nginx+php+mysql的詳細(xì)教程 的相關(guān)資料,需要的朋友可以參考下2016-09-09
基于php偽靜態(tài)的實(shí)現(xiàn)詳細(xì)介紹
本篇文章介紹了,基于php偽靜態(tài)的實(shí)現(xiàn)詳細(xì)分析。需要的朋友參考下2013-04-04

