zoukankan      html  css  js  c++  java
  • yii2 插件使用

    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;
            }
    View Code

    前端

    引入
    use kartikgridGridView;
    
     'export' => false,//使用kar.必须进行此处配置
    
                [
                    'class' => 'kartikgridEditableColumn',
                    'attribute' => 'name',
                    'editableOptions' => [
                        'placement' => 'right',
                        'header' => '广告名称',
                        'size' => 'md'
                    ],
                    'vAlign' => 'middle',
                    'format' => 'raw',
                ],
    View Code

     状态切换

                [
                    '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(),
    
                ],
    View Code

     多选

      [
                    '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
                                        ],
                                ],
                        ];
                    },
                ],
    View Code
  • 相关阅读:
    [bzoj3218] a+b problem [最小割+数据结构优化建图]
    [bzoj3456] 城市规划 [递推+多项式求逆]
    [ARC068F] Solitaire [DP]
    [bzoj3601] 一个人的数论 [莫比乌斯反演+高斯消元]
    [中山市选2011][bzoj2440] 完全平方数 [二分+莫比乌斯容斥]
    [bzoj2159] Crash的文明世界 [斯特林数+树形dp]
    [bzoj2839] 集合计数
    通用解题方法—回溯法
    分支限界法—单源最短路径问题
    分支限界法
  • 原文地址:https://www.cnblogs.com/huay/p/11510688.html
Copyright © 2011-2022 走看看