mysam/sortable-behavior-bundle

提供了一种对管理员列表进行排序的方法

1.5.3 2020-10-16 12:48 UTC

This package is auto-updated.

Last update: 2024-09-16 21:37:16 UTC


README

为您的Symfony2管理员列表提供可排序功能

SonataAdminBundle实现

SonataAdminBundle在此提供了配方文章

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

配置

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

# app/config/config.yml
pix_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操作中的模板更改为PixSortableBehaviorBundle:Default:_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' => 'AppBundle:Admin:_sort_drag_drop.html.twig',
                        'enable_top_bottom_buttons' => true, //optional
                    ),
                ),
            ))
        ;
    }

此外,在您的theme.yml文件中添加以下两行以包含使此功能正常工作的JavaScript

    //...
    javascripts:
        - bundles/pixsortablebehavior/js/jquery-ui.min.js // if you haven't got jQuery UI yet.
        - bundles/pixsortablebehavior/js/init.js

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

pixSortableBehaviorBundle.success
pixSortableBehaviorBundle.error

禁用顶部和底部按钮

<?php

    // ClientAdmin.php
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
            ->add('enabled')
            ->add('_action', null, array(
                'actions' => array(
                    'move' => array(
                        'template' => 'PixSortableBehaviorBundle:Default:_sort_drag_drop.html.twig',
                        'enable_top_bottom_buttons' => true,
                    ),
                ),
            ))
        ;
    }