yii2 GridView全选、反选

<?php
                        echo GridView::widget([
                            'dataProvider' => $dataProvider,
                            //每列都有搜索框 控制器传过来$searchModel = new ArticleSearch();
                            //'filterModel' => $searchModel,
                            'layout'=> '{items}<div class="text-right tooltip-demo">{pager}</div>',
                            'pager'=>[
                                //'options'=>['class'=>'hidden']//关闭自带分页
                                'firstPageLabel'=>"首页",
                                'prevPageLabel'=>'上一页',
                                'nextPageLabel'=>'下一页',
                                'lastPageLabel'=>'未页',
                            ],
                            'columns' => [
//                                ['class' => 'yii\grid\SerialColumn'],//不需要显示前面的导航
                                [
                                    'attribute' => '',
                                    'format' => ['raw'],
                                    'label' => "全/反选",
                                    'headerOptions' => ['width' => '50','style'=>'cursor:pointer'],
                                    'contentOptions' => ['align'=>'center'],
                                    'header'=>"<b title='全选' id='all-check'>全</b>/<b title='反选' id='reverse-check'>反</b>",
                                    'value' => function ($data) {
                                        return "<input type='checkbox' class='i-checks' value={$data['id']}>";
                                    },
                                ],
                                [
                                    'attribute' => '',
                                    'label' => '游戏名',
                                    'headerOptions' => ['width' => '100'],
                                    'value' => function($data){
                                        return $img = empty(Yii::$app->params['indexParams'][$data['gameid']]) ? '' :Yii::$app->params['indexParams'][$data['gameid']];
                                    }
                                ],
                                [
                                    'attribute' => '',
                                    'label' => '渠道号',
                                    'headerOptions' => ['width' => '50'],
                                    'value' => 'agent'
                                ],
                                [
                                    'attribute' => '',
                                    'label' => '平台',
                                    'format' => ['raw'],
                                    'headerOptions' => ['width' => '50'],
                                    'value' => function($data){
                                        $html = '';

                                        if ($data['platform'] == 1) {
                                            $html = '<i class="fa fa-android" style="font-size: 20px"></i>';
                                        } elseif ($data['platform'] == 2) {
                                            $html = '<i class="fa fa-apple" style="font-size: 20px"></i>';
                                        }

                                        return $html;
                                    }
                                ],
                                [
                                    'attribute' => '',
                                    'label' => '证书id',
                                    'headerOptions' => ['width' => '50'],
                                    'value' => 'auth_id'
                                ],
                                [
                                    'attribute' => '',
                                    'label' => '创建时间',
                                    'headerOptions' => ['width' => '120'],
                                    'value' => function($data){
                                        return date('Y-m-d H:i:s', $data['created_at']);
                                    },
                                ],
                                [
                                    'attribute' => '',
                                    'label' => '更新时间',
                                    'headerOptions' => ['width' => '120'],
                                    'value' => function($data){
                                        return $data['updated_at'] ? date('Y-m-d H:i:s', $data['updated_at']) : '--';
                                    },
                                ],
                                [
                                    'attribute' => '',
                                    'label' => '分包状态',
                                    'headerOptions' => ['width' => '100'],
                                    'value' => function ($data) {
                                        $ttMap = Yii::$app->params['ttMap'];
                                        $position = isset($ttMap[$data['id']])?'-'.$ttMap[$data['id']]:'';
                                        return Yii::$app->params['statusMap'][$data['status']].$position;
                                    },

                                ],
                                [
                                    'attribute' => '',
                                    'label' => '分包信息',
                                    'value' => 'remark',
                                    'headerOptions' => ['width' => '100'],
                                ],
                                ['class' => 'yii\grid\ActionColumn', 'header' => '操作', 'template' => '{update}   {delete}',
                                    'buttons' => [
                                        'update' => function ($url, $data) {

                                            $html = Html::button('发起分包', ['class' => 'btn disabled', 'disabled' => 'disabled']);

                                            if ($data['status'] == 2) {
                                                $url = Url::to(['game/re-sub']);
                                                $params = json_encode(['ids' => [$data['id']]]);
                                                $html = Html::a('发起分包', 'javaScript:;', ['class' => 'ajax-link', 'data-url' => $url, 'data-params' => $params]);
                                            }

                                            return $html;

                                        },
                                        'delete' => function ($url, $data) {
                                            $dataParams = json_encode(['id' => $data['id']]);
                                            $url = Url::to(['game/sub-del']);

                                            return Html::a('<span class="glyphicon glyphicon-remove ">删除</span>', 'javascript:;', ['title' => '删除分包', 'id' => $data['id'], 'class' => 'ajax-link', 'data-url' => $url, 'data-params' => $dataParams]);
                                        },
                                    ],
                                    'headerOptions' => ['width' => '150']
                                ],
                            ],
                            'emptyText' => '没有筛选到任何内容哦',
                        ]);
                        ?>
  //全选
            $('#all-check').click(function(){
                var divElement = $(".i-checks").parent('div');
                $(divElement).each(function(){
                    $(this).addClass("checked")
                });
            });

            //反选
            $('#reverse-check').click(function(){
                var divElement = $(".i-checks").parent('div');
                $(divElement).each(function(){
                    if($(this).hasClass('checked')){
                        $(this).removeClass('checked');
                    }else{
                        $(this).addClass("checked")
                    }
                });
            });


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页