GridView插件
行内文本编辑
后端
if (Yii::$app->request->post('hasEditable')) { $id = Yii::$app->request->post('editableKey'); $model = ModulePosition::findOne($id); $out = ['output' => '', 'message' => '']; $posted = current($_POST['ModulePosition']); $post = ['ModulePosition' => $posted]; if ($model->load($post) && $model->save(false)) { $out = ['output' => '', 'message' => '']; } else { $out['message'] = $model->getErrors(); } echo Json::encode($out); return; }
前端
引入 use kartikgridGridView; 'export' => false,//使用kar.必须进行此处配置 [ 'class' => 'kartikgridEditableColumn', 'attribute' => 'name', 'editableOptions' => [ 'placement' => 'right', 'header' => '广告名称', 'size' => 'md' ], 'vAlign' => 'middle', 'format' => 'raw', ],
状态切换
[ 'class' => 'kartikgridEditableColumn', 'attribute' => 'status', 'value' => function ($model) { return jrhbadminmodelsReport::getReportStatus()[$model->status]; }, 'format' => 'raw', 'headerOptions' => ['width' => '80px'], 'editableOptions' => [ 'placement' => 'left', 'inputType' => Editable::INPUT_DROPDOWN_LIST, 'data' => jrhbadminmodelsReport::getReportStatus(), ], 'filter' => jrhbadminmodelsReport::getReportStatus(), ],
多选
[ 'label'=>'标签', 'attribute'=>'tag', 'class'=>'kartikgridEditableColumn', 'value'=>function($model){ if($model->tag){ return implode(',',$model->tag); }else{ return ''; } }, 'editableOptions'=>function($model){ $data=ArrayHelper::map(Tag::find()->all(),'tag','tag'); if($model->profile->tag){ $model->tag=explode(',',$model->profile->tag); $data=array_merge($data, array_combine($model->tag,$model->tag)); } return [ 'placement'=>'left', 'size'=>'md', 'inputType'=>kartikeditableEditable::INPUT_SELECT2, 'options'=>[ 'data' => $data, 'options' => ['multiple' => true], 'pluginOptions' => [ 'tags' => true, 'tokenSeparators' => [',', ' '], 'maximumInputLength' => 10 ], ], ]; }, ],