codeclipse / sortable-behavior-bundle

提供了一种排序管理列表的方法

安装: 81

依赖者: 0

推荐者: 0

安全性: 0

星标: 0

关注者: 0

分支: 78

类型:symfony-bundle

v2.0 2022-06-26 10:02 UTC

This package is auto-updated.

Last update: 2024-09-26 15:08:01 UTC


README

本包是基于 https://github.com/pix-digital/pixSortableBehaviorBundle 的分支

SonataAdminBundle 实现

SonataAdminBundle 提供了以下文档中的食谱文章

https://github.com/sonata-project/SonataAdminBundle/blob/4.x/docs/cookbook/recipe_sortable_listing.rst

配置

默认情况下,此扩展与 Doctrine ORM 一起工作,但您可以通过定义驱动程序配置来选择使用 Doctrine MongoDB。

# config/packages/codeclipse_sortable_behavior.yaml
codeclipse_sortable_behavior:
    db_driver: mongodb # default value : orm
    position_field:
        default: sort #default value : position
        entities:
            AppBundle\Entity\Foobar: order
            AppBundle\Entity\Baz: rang
    sortable_groups:
        entities:
            AppBundle\Entity\Baz: [ group ]
            

使用可拖动的列表而不是上下按钮

要使用可拖动的列表而不是上下按钮,请将 move 动作中的模板更改为 @CodeclipseSortableBehavior/Default/_sort_drag_drop.html.twig

<?php

    // ClientAdmin.php
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
            ->add('enabled')
            ->add(ListMapper::NAME_ACTIONS, null, [
                'actions' => [
                    'move' => [
                        'template' => '@AppBundle/Admin/_sort_drag_drop.html.twig',
                        'enable_top_bottom_buttons' => false, // enabled by default
                    ],
                ],
            ])
        ;
    }

此外,在您的 theme.yml 文件中包含此功能所需的 JavaScript,添加以下两行

    //...
    javascripts:
        - bundles/codeclipsesortablebehavior/vendor/jquery-ui.min.js // if you haven't got jQuery UI yet.
        - bundles/codeclipsesortablebehavior/js/app.js

添加 JavaScript 和模板将允许您在表格列表中拖动项目。如果需要,此插件在拖动 $(document) 元素时触发 jQuery 事件,因此如果需要添加自定义通知,这是可能的。此外,当拖动时,<body> 获得一个 is-dragging 类。当停止拖动时,此类将被删除。如果您有自定义的 js/css,这将非常有用。

codeclipseSortableBehaviorBundle.success
codeclipseSortableBehaviorBundle.error

禁用顶部和底部按钮

<?php

    // ClientAdmin.php
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
            ->add('enabled')
            ->add(ListMapper::NAME_ACTIONS, null, [
                'actions' => [
                    'move' => [
                        'template' => '@CodeclipseSortableBehavior/Default/_sort_drag_drop.html.twig',
                        'enable_top_bottom_buttons' => false,
                    ],
                ],
            ])
        ;
    }