\kartik\editable\Editable 插件的前端和后端的实现 [ 2.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'=>'']);
}
蛋黄派
注册时间:2015-02-27
最后登录:2017-01-19
在线时长:10小时36分
最后登录:2017-01-19
在线时长:10小时36分
- 粉丝10
- 金钱240
- 威望60
- 积分940
共 1 条评论
\kartik\editable\Editable 插件这个能发出来吗