蛋黄派 2015-02-27 18:17:27 7149次浏览 1条评论 1 0 0

view 中的代码

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\CheckboxColumn'],

        'id',
        'title',
        [
            'label'=>'客户端推荐',
            'format'=>'raw',这里输入代码
            'value' => function($model){
            return \kartik\editable\Editable::widget([
                'name'=>'client_recommend',

                'value' =>$model->client_recommend==0?'X':'√',
                'attribute'=>'client_recommend',
                'header' => '客户端推荐',
                'size'=>'md',
                'formOptions'=>[
                    'method'=>'post',
                    'action'=> Yii::$app->urlManager->createAbsoluteUrl(['/web-event-info/editable-demo','id'=>$model->id])
                ],
                //'format' => Editable::FORMAT_LINK,
                'format' => 'button',
                'inputType' => Editable::INPUT_DROPDOWN_LIST,
                'data'=>[
                    0 =>'X',
                    1 =>'√'
                ],
                'options' => ['class'=>'form-control', 'placeholder'=>'Enter person name...'],
                //'editableValueOptions'=>['class'=>'well well-sm']

            ]);

            }
        ],
        [
            'class' => 'yii\grid\ActionColumn',
            'header'=>'操作',
            //'template' => '{audit} {view} {update} {delete}',
            //'buttons' => [
            //'audit' => function ($url, $model, $key) {
            //return
            //Html::a('<span class="glyphicon glyphicon-user"></span>', $url, ['title' => '审   核'] );
            //},
            //],
            'headerOptions' => ['width' => '100']
        ],

    ],
]);
?>

controller

public function actionEditableDemo($id) {
    $model = EventInfo::findOne($id);

//设置是否客户端推荐
if (isset($_POST['client_recommend'])) {
    $model->client_recommend = (int)$_POST['client_recommend'];
    $model->updateAll([ 'client_recommend'=> (int)$_POST['client_recommend']], ['id' => $id]);
    $value = $model->client_recommend == 0? 'X':'√';
         Yii::error("load:".$_POST['client_recommend']);
    echo \yii\helpers\Json::encode(['output'=>$value, 'message'=>'']);
}
您需要登录后才可以评论。登录 | 立即注册