quansitech / qscmf-list-search-type-select2
qscmf list builder search select2
v1.1.0
2024-03-27 05:55 UTC
Requires
- php: >=7.2
- tiderjian/think-core: >=11.0
This package is auto-updated.
Last update: 2024-11-27 07:28:51 UTC
README
qscmf 列表搜索控件--select2
下拉框模糊搜索,支持多选
安装
composer require quansitech/qscmf-list-search-type-select2
添加下拉框模糊搜索控件
-
简单用法,添加单选下拉框模糊搜索筛选项
-
键值对数据格式
$user_list = D("User")->getField("id,name", true); (new \Qscmf\Builder\ListBuilder()) ->addSearchItem('user_id', 'select2', '单选姓名', $user_list) ->display();
-
需要分组的数据格式
for ($i=1;$i<=5;$i++){ $children = []; for ($j=1;$j<=3;$j++){ $children[] = ['id' => $i.'_'.$j, 'text' => $j.'子分类']; } $cate_list[] = ['text' => '父级分类'.$i, 'children' => $children]; } (new \Qscmf\Builder\ListBuilder()) ->addSearchItem('cate_id', 'select2', '单选分类', $cate_list) ->display();
-
-
高级用法,可自定义下拉框宽度,支持多选等
多选的数据格式为选中值以英文逗号拼接如,id1,id2,id3
$user_list = D("User")->getField("id,name", true); // 该值为Select2Builder对象 $select2_obj = new Select2Builder($user_list); $select2_obj->setPlaceholder("请选择多选姓名"); $select2_obj->setIsMultiple(true); $select2_obj->setWidth("100"); (new \Qscmf\Builder\ListBuilder()) ->addSearchItem('select2_obj', 'select2', '多选姓名', $select2_obj) ->display();
-
快速拼接数据库查询条件
通过parse可快速从请求参数中组装数据库查询条件,而无需关心组件的数据格式
//$key 搜索栏name //$map_key 数据库字段值 //$get_data $_GET数组 // 返回值 // [$map_key => $get_data[$key]] $map = array_merge($map, \Qs\ListSearchType\Select2\Select2::parse('project_id', 'project_id', $get_data));