totocsa/yii2-multiselect

基于 Bootstrap 4 的网格视图多选功能

安装: 8

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

公开问题: 0

类型:yii2-extension

dev-master 2020-10-18 22:08 UTC

This package is auto-updated.

Last update: 2024-09-19 06:39:01 UTC


README

Bootstrap 4 网格视图多选功能

安装

安装此扩展的首选方法是通过 composer

可以运行

php composer.phar require --prefer-dist totocsa/yii2-multiselect "dev-master"

或者在您的 composer.json 文件的 require 部分添加

"totocsa/yii2-multiselect": "dev-master"

到您的代码中

使用方法

扩展安装后,只需在代码中简单使用即可

在网格视图中

[
    'attribute' => 'statusid',
    'value' => function($model, $key, $index, $column) {
        /* @var $model app\models\Human */
        return $model->status->name;
    },
    'filter' => MultiSelect::widget([
        'model' => $searchModel,
        'attribute' => 'statusid',
        'items' => ArrayHelper::map(Status::find()
                        ->orderBy(['name' => SORT_ASC])
                        ->all(), 'id', 'name'),
    ]),
],

在搜索文件中

public function init() {
    parent::init();

    $this->statusid = ArrayHelper::getColumn(Status::find()
                            ->orderBy(['name' => SORT_ASC])
                            ->all(), 'id');
}

public function rules() {
    return [
    ...
        [['statusid', 'vehicleid', 'operatingsystemid'], 'each', 'rule' => ['integer']],
    ...
    ];
}

public function search($params) {
...
    if (is_array($this->statusid)) {
        if (count($this->statusid) > 0) {
            $query->andFilterWhere(['in', 'human.statusid', $this->statusid]);
        } else {
            $query->andWhere('false');
        }
    } else {
        $query->andWhere('false');
    }
....
}