如何在GridView小部件YII2中的一列中添加这两个类

时间:2016-08-31 14:39:03

标签: php yii2

我需要在同一列中添加序列类和复选框类。请尽快帮助我。谢谢...

     <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
    ['class' => 'yii\grid\CheckboxColumn',
        'header' => '',
        'checkboxOptions' => function($model) {
        if($model->featured=="Y"){
          $bool =true;  
        }else{
            $bool =false;  
        }

         return ['checked' => $bool,'value'=>$model->user_id];},'contentOptions' => ['style'=>'text-align: center;font-size: 13px;',],
        ],

        ['class' => 'yii\grid\SerialColumn',
        'header' => 'S.No',
        'headerOptions' => ['style'=>'text-align: center;background-color: #868686;color: white;font-size: 13px;font-weight: bold;',],
        'contentOptions' => ['style'=>'text-align: center;font-size: 13px;',],
        ],
], ]); ?>

1 个答案:

答案 0 :(得分:0)

Coud你需要格式=&gt;原始和使用匿名函数的价值像这个建议

<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
    ['class' => 'yii\grid\CheckboxColumn',
    'header' => '',
    'format' => 'raw',
    'value' => function($model,  $key, $index) {
        return "<input type='checkbox' name='select[]' ><span> <?= $index ?></span>"
    },
     ....
    ],

    .....
], ]); ?>