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 kartik\grid\GridView; 'export' => false,//使用kar.必须进行此处配置 [
'class' => 'kartik\grid\EditableColumn',
'attribute' => 'name',
'editableOptions' => [
'placement' => 'right',
'header' => '广告名称',
'size' => 'md'
],
'vAlign' => 'middle',
'format' => 'raw',
],

状态切换

            [
'class' => 'kartik\grid\EditableColumn',
'attribute' => 'status',
'value' => function ($model) {
return \jrhbadmin\models\Report::getReportStatus()[$model->status];
},
'format' => 'raw',
'headerOptions' => ['width' => '80px'],
'editableOptions' => [
'placement' => 'left',
'inputType' => Editable::INPUT_DROPDOWN_LIST,
'data' => \jrhbadmin\models\Report::getReportStatus(),
],
'filter' => \jrhbadmin\models\Report::getReportStatus(), ],

多选

  [
'label'=>'标签',
'attribute'=>'tag',
'class'=>'kartik\grid\EditableColumn',
'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'=>\kartik\editable\Editable::INPUT_SELECT2,
'options'=>[
'data' => $data,
'options' => ['multiple' => true],
'pluginOptions' => [
'tags' => true,
'tokenSeparators' => [',', ' '],
'maximumInputLength' => 10
],
],
];
},
],

yii2 插件使用的更多相关文章

  1. yii2集成富文本编辑器redactor

    作者:白狼 出处:http://www.manks.top/article/yii2_redactor本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保 ...

  2. apache服务器yii2报The fileinfo PHP extension is not installed解决思路

    这个问题整整困扰了我两天,今天终于搞定了.记录一下. 背景是这样的,我呢,在centos服务器上安装了lamp环境,其中php是5.3.3,在用composer安装yii2的时候,出现了某些yii2插 ...

  3. Yii2系列教程六:集成编辑器

    上一篇文章我们实现了简单的用户权限管理,至于更先进的RBAC,我后面会单独出一篇文章来说说.在这一篇文章当中,我主要想写的是在Yii2中集成一个编辑器,因为在我们的实际开发当中,一个简单的textar ...

  4. linux--->阿里云centos6.9安装yii2报错

    阿里云centos6.9安装yii2报错 错误显示:Warning: require(/vendor/autoload.php): failed to open stream: No such fil ...

  5. yii2组件之多图上传插件FileInput的详细使用

    作者:白狼 出处:http://www.manks.top/yii2_multiply_images.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连 ...

  6. Yii2 手动安装yii2-imagine插件

    由于网络的原因使用composer安装Yii框架,实在太过痛苦,所以这里干脆就手动安装yii-imagine的扩展. 首先下载yii2-image和Imagine扩展库,点击链接就可以从百度云下载上传 ...

  7. yii2.0使用bootstrap中日期插件

    Yii2框架引用bootstrap中日期插件yii2-date-picker的方法. 使用composer安装 日期插件 php composer.phar require "2amigos ...

  8. yii2 开源插件与系统

    yii2干货集:https://github.com/forecho/awesome-yii2 商城 samdark/yii2-shop composer global require "f ...

  9. window yii2 安装插件 报yiisoft/yii2 2.0.x-dev requires ext-mbstring错

    Problem 1 - yiisoft/yii2 2.0.x-dev requires ext-mbstring * -> the requested PHP extens ion mbstri ...

随机推荐

  1. nginx启动报错nginx: [error] open() "/usr/local/etc/nginx/logs/nginx.pid" failed

    问题:nginx启动的时候会报丢失pid的错误 nginx: [error] open() “/usr/local/var/run/nginx.pid” failed 解决方案: sudo nginx ...

  2. 面试突击 | Redis 如何从海量数据中查询出某一个 Key?附视频

    1 考察知识点 本题考察的知识点有以下几个: Keys 和 Scan 的区别 Keys 查询的缺点 Scan 如何使用? Scan 查询的特点 2 解答思路 Keys 查询存在的问题 Scan 的使用 ...

  3. C#连接数据库的方法

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  4. Ant Design 方法默认传值,加上其他参数

    前端填坑之路Ant Design里面的一些触发方法,如OnChange,OnSelect等等,当你触发时,该时间会自动传一些值给方法. 这是Select里面的onChange调用,在红框中,他会自动传 ...

  5. Bootstrap 手机屏幕自适应的响应式布局开关

    head中添加 <meta name="viewport" content="width=device-width, initial-scale=1, shrink ...

  6. JQuery调用WebService封装方法

    //提交的webservice链接 //var url = "/wsstafffrate?OpenWebService"; //请求前拼接好的soap字符串 //var soapd ...

  7. PTA 邻接表存储图的广度优先遍历

    试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(Vertex) ) 其中LGraph是邻接表存储的 ...

  8. spring cloud config---Could not resolve placeholder 'xxx' in string value "${xxx}"

    初学SpringCloud 跟着视频写配置 前前后后检查了许久,配置代码没问题 最后发现是client项目的配置文件名有问题,不应该是application.yml 而是bootstrap.yml 那 ...

  9. PHP Magic Method Setter and Getter

    <?php /* Magic method __set() and __get() 1.The definition of a magic function is provided by the ...

  10. JS中BOM操作知识点

    JS BOM window对象 全局变量和全局方法都归在window上 alert-comfirm-prompt 让alert .confirm等弹出框上的提示文字实现换行:\n // confirm ...