小叮当的肚兜 2019-03-04 15:39:32 1088次浏览 1条评论 3 0 0

https://github.com/nick-denry/yii2-round-switch-column 此扩展是在 GridView 中添加一个字段的开关,非常好用。不依赖其他扩展。(搬运) 效果图:

深度截图_选择区域_20190304153255.png

配置:

//1,main.php 添加组件
'modules' => [
    'roundSwitch' => [
        'class' => 'nickdenry\grid\toggle\Module',
    ],
]
//2,GridView 使用
先use nickdenry\grid\toggle\components\RoundSwitchColumn;
然后:
[
    'class' => RoundSwitchColumn::class,
    'attribute' => 'active',
    'headerOptions' => ['width' => 150],//列长
],
//3,控制器配置
Controller config
Add toggleAction to your Controller

use nickdenry\grid\toggle\actions\ToggleAction;

public function actions()
{
   return [
        'toggle' => [
            'class' => ToggleAction::class,
            'modelClass' => 'common\models\Model', // Your model class
        ],
    ];
}

注:默认类型是 0/1 可在model文件中定义此值,

//例:
 /**
 * @var array
 */
public $switchValues = [
    'isHot' => [
        'on' => 10,
        'off' => 0,
    ],
    'isRecommend' => [
        'on' => 10,
        'off' => 0,
    ],
];
亿速云
您需要登录后才可以评论。登录 | 立即注册