paysera / fork-pix-digital-pix-sortable-behavior-bundle

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

v1.4.2 2017-12-26 13:58 UTC

README

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

SonataAdminBundle实现

SonataAdminBundle在这里提供了一个配方文章

https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/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操作中的模板更改为AppBundle:Admin:_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' => 'AppBundle:Admin:_sort.html.twig',
                        'enable_top_bottom_buttons' => true,
                    ),
                ),
            ))
        ;
    }