runroom / sortable-behavior-bundle
此包已被废弃,不再维护。作者建议使用runroom-packages/sortable-behavior-bundle包。
1.2.0
2020-02-24 14:33 UTC
Requires
- php: ^7.3
- doctrine/common: ^2.12
- symfony/config: ^4.4 || ^5.0
- symfony/dependency-injection: ^4.4 || ^5.0
- symfony/http-foundation: ^4.4 || ^5.0
- symfony/http-kernel: ^4.4 || ^5.0
- symfony/property-access: ^4.4 || ^5.0
- symfony/translation: ^4.4 || ^5.0
- twig/twig: ^2.12 || ^3.0
Requires (Dev)
- doctrine/orm: ^2.7
- gedmo/doctrine-extensions: ^2.4
- sonata-project/admin-bundle: ^3.58
Suggests
- sonata-project/admin-bundle: Can be easily integrated with Sonata Admin bundle
- stof/doctrine-extensions-bundle: Manage doctrine extensions with Symfony
This package is auto-updated.
Last update: 2020-03-16 16:43:32 UTC
README
为您的Symfony管理列表提供可排序功能
配置
默认情况下,此扩展与Gedmo DoctrineExtensions一起工作,但您可以更改位置处理器或实现自己的(有三种实现:Gedmo、ORM和ODM)
# app/config/config.yml sortable_behavior: position_handler: sortable_behavior.position.orm position_field: default: sort # default value: position entities: AppBundle\Entity\Foobar: order AppBundle\Entity\Baz: rang sortable_groups: entities: AppBundle\Entity\Baz: [ group ]
正常使用
要在sonata上使用此包,您需要配置一个自定义模板的操作。
<?php // ClientAdmin.php protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('name') ->add('enabled') ->add('_action', null, array( 'actions' => array( 'move' => array( 'template' => '@SortableBehavior/sort.html.twig', 'enable_top_bottom_buttons' => true, //optional ), ), )) ; }
使用可拖动列表代替上下按钮
要使用可拖动列表而不是上下按钮,将move
操作中的模板更改为@SortableBehavior/sort_drag_drop.html.twig
。
<?php // ClientAdmin.php protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('name') ->add('enabled') ->add('_action', null, array( 'actions' => array( 'move' => array( 'template' => '@SortableBehavior/sort_drag_drop.html.twig', 'enable_top_bottom_buttons' => true, // optional ), ), )) ; }
此外,在您的theme.yml
文件中包含所需的JavaScript,添加以下两行
//... javascripts: - bundles/sortablebehavior/js/jquery-ui.min.js // if you haven't got jQuery UI yet. - bundles/sortablebehavior/js/init.js
添加JavaScript和模板后,您将能够拖动表中的项。如果需要,此插件在$(document)
元素上完成拖动时触发jQuery事件,因此如果您想添加自定义通知,这是可能的。此外,当拖动时,<body>
将获得is-dragging
类。当您停止拖动时,此类将被移除。如果您的自定义js/css需要这个功能,这将非常有用。
SortableBehaviorBundle.success
SortableBehaviorBundle.error