码迷,mamicode.com
首页 > 其他好文 > 详细

YIi2中checkboxOptions前选框的用法

时间:2015-08-03 14:21:51      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

这是checkboxOptions前选框的用法

use yii\grid\GridView;

$this->registerJs("

    $(‘#selection_all‘).click(function(){

        $(‘input[name=selection_all]‘).click();

    });

 

    $(‘#delete_select‘).click(function(){

        var selection = $(‘#w0‘).yiiGridView(‘getSelectedRows‘);

        if(selection.length==0){

            alert(‘未选中‘);

            return false;

        }else{

            if(confirm(‘您确定要删除吗?‘)==true){

               $.post(‘".Url::to([‘product-base/delete-select‘])."‘, {selection:selection});

               location=location;

            }else{

               location=location;

            }        

        }

});

 

    $(‘#up_select‘).click(function(){

        var selection = $(‘#w0‘).yiiGridView(‘getSelectedRows‘);

        if(selection.length==0){

            alert(‘未选中‘);

            return false;

        }else{

            $.post(‘".Url::to([‘product-base/status-select‘])."‘, {selection:selection,status:1});

            location=location;

        }

    });

 

    $(‘#down_select‘).click(function(){

        var selection = $(‘#w0‘).yiiGridView(‘getSelectedRows‘);

        if(selection.length==0){

            alert(‘未选中‘);

            return false;

        }else{

            $.post(‘".Url::to([‘product-base/status-select‘])."‘, {selection:selection,status:0});

            location=location;

        }

    });

", \yii\web\View::POS_END);

 

<?= GridView::widget([

          ‘layout‘ => "{items}<div class=‘row‘>

               <div class=‘btn-group col-md-3‘>

                 <button class=‘btn btn-warning‘ id=‘selection_all‘>全选</button>

                 <button class=‘btn btn-default‘ id=‘up_select‘>上架</button>

                 <button class=‘btn btn-default‘ id=‘down_select‘>下架</button>

                 <button class=‘btn btn-default‘ id=‘delete_select‘>删除</button>

               </div>

               <div class=‘col-md-7‘ style=‘margin-top:-20px‘>

               {pager}</div>

                            </div>

               ",

   

        ‘dataProvider‘ => $dataProvider,

        ‘columns‘ => [

            [‘class‘ => ‘yii\grid\SerialColumn‘],

            [‘class‘ => ‘yii\grid\CheckboxColumn‘,

                ‘checkboxOptions‘ => function($model, $key, $index, $column) {

                    return [‘value‘ => $model->id];

                }],

            [‘class‘ => ‘yii\grid\ActionColumn‘],

            [

                ‘label‘ => ‘更多操作‘,

                ‘format‘=>‘raw‘,

                ‘value‘ => function($model){

                    return Html::a(‘店铺商品列表‘, [‘product/index‘,‘id‘ => $model->id], [‘title‘ => ‘店铺商品列表‘]);

                }

            ],

        ],

]); ?>

 

 

Controller中的写法:

   public function actionDeleteSelect(){

        //删除selection

        $selection = Yii::$app->request->post(‘selection‘);

        ProductBase::deleteAll([‘id‘=>$selection]);

    }

 

    //改变状态

    public function actionStatusSelect(){

        //找到选中的

        $selection = Yii::$app->request->post(‘selection‘);

        //找到post过来的

        $status = Yii::$app->request->post(‘status‘);

        ProductBase::updateAll([‘status‘=>$status],[‘id‘=>$selection]);

    }

YIi2中checkboxOptions前选框的用法

标签:

原文地址:http://www.cnblogs.com/wangjinke/p/4699184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!