totocsa / yii2-multiselect
基于 Bootstrap 4 的网格视图多选功能
dev-master
2020-10-18 22:08 UTC
Requires
- yiisoft/yii2: ~2.0.0
Suggests
- yiisoft/yii2-bootstrap4: The Yii 2 Bootstrap 4 extension must be installed separately for this extension to work.
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'); } .... }