pixassociates/sortable-behavior-bundle

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

安装量: 1,413,922

依赖关系: 6

建议者: 1

安全性: 0

星标: 46

关注者: 4

分支: 78

公开问题: 13

类型:symfony-bundle

v1.5 2018-03-26 15:56 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:09:09 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,
                    ),
                ),
            ))
        ;
    }