atlant5 / handpicked-list
为 Yii2 设计的小部件(助手)。基于 Bootstrap。帮助你构建管理界面。你可以在漂亮的弹出窗口中选择一些元素,并在另一个紧凑的漂亮界面上查看所选项目。
Requires
- php: >=5.4.0
- yiisoft/yii2: ^2.0.0
This package is not auto-updated.
Last update: 2024-09-29 03:58:07 UTC
README
此小部件可以帮助你构建管理界面。你可以在漂亮界面上选择一些元素,并在另一个漂亮紧凑界面上查看所选项目。
功能
- 如果你想的话,“只读”条件
- 在元素中轻松搜索
- Bootstrap 管理LTE集成
用法
在视图中
<?= HandpickedList::widget([
'dataProvider' => $handpickedListProvider,
'modelWithRelations' => 'GeneralPages[manageWidgets]',
'title' => 'Блоки страницы',
'readOnly' => false,
'collapse' => true,
'usingColumns' => ['id', 'name', 'code', 'own_description'],
'customSelectionColumn' => 'id',
'customSelection' => $selectedItems,
]) ?>
禁用所有选项
<?= HandpickedList::widget([
'dataProvider' => $handpickedListProvider,
'modelWithRelations' => 'GeneralPages[manageWidgets]',
'title' => 'Блоки страницы',
'readOnly' => true,
'collapse' => false,
'usingColumns' => ['id', 'name', 'code', 'own_description'],
'customSelectionColumn' => 'id',
'customSelection' => $selectedItems,
]) ?>
关于选项
1. dataProvider (数组 | 对象)
看起来像
'dataProvider' => $handpickedListProvider,
$handpickedListProvider 必须是一个数组
[
0 => [
'name' => 'название'
'code' => '123'
'checked' => false
'type' => ''
'id' => '4'
]
1 => [
'name' => 'Второй блок для теста'
'code' => 'html2'
'checked' => true
'type' => ''
'id' => '5'
]
]
或者来自 ArrayDataProvider 的对象
yii\data\ArrayDataProvider#1
(
[key] => null
[allModels] => [
0 => [
'id' => '4'
'code' => '123'
'name' => 'название'
'own_description' => 'примечание'
]
1 => [
'id' => '5'
'code' => 'html2'
'name' => 'Второй блок для теста'
'own_description' => ''
]
]
[modelClass] => null
[id] => null
[yii\data\BaseDataProvider:_sort] => null
[yii\data\BaseDataProvider:_pagination] => null
[yii\data\BaseDataProvider:_keys] => null
[yii\data\BaseDataProvider:_models] => null
[yii\data\BaseDataProvider:_totalCount] => null
[yii\base\Component:_events] => []
[yii\base\Component:_behaviors] => null
2. usingColumns (数组)
用于在组件中显示的列。例如
'usingColumns' => ['id', 'name', 'code'],
第一个正常列将是元素的文本标题。这里是 'name'
3. customSelectionColumn (字符串)
检测所选元素的列名称。默认 = 'id'
4. customSelection (数组)
customSelectionColumn 中所选元素的数组。例如
'customSelection' => [4, 5]
这意味着 ID 为 4 和 5 的元素将被选择
5. detectedColumns (数组)
键 - 值数组,其中 '键' 是列 '值' 是值。例如
'detectedColumns' => ['code' => 123];
代码等于 123 的每个元素都将被选择。
你可以制定许多规则:'detectedColumns' => ['code' => 123, 'id' => '5']; ,但请不要创建它 :-)
默认 ['active' => true]
6. modelWithRelations (字符串)
指定将保存输入数据(所选项目)的模型和关系名称。例如:'modelWithRelations' => 'GeneralPages'
或者
'modelWithRelations' => 'GeneralPages[manageWidgets][anyRelation]'
在视图中 'modelWithRelations' => 'GeneralPages[manageWidgets]' 显示为
<input type="hidden" name="GeneralPages[manageWidgets][]" value="5">
并通过 manageWidgets 关系保存。
p.s.
抱歉这种丑陋的方法
帮助我创建一个良好的解决方案。
警告!
小部件没有分页!如果你有超过 1000 个元素,不要使用它。
关于
在 GitHub 上:https://github.com/EvgenyVetrov/handpicked-list
在 Packagist 上:https://packagist.org.cn/packages/atlant5/handpicked-list




