Code Monkey home page Code Monkey logo

fork-pix-digital-pix-sortable-behavior-bundle's Introduction

pixSortableBehaviorBundle

Offers a sortable feature for your Symfony2 admin listing

SonataAdminBundle implementation

The SonataAdminBundle provides a cookbook article here :

https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe_sortable_listing.rst

Configuration

By default, this extension works with Doctrine ORM, but you can choose to use Doctrine MongoDB by defining the driver configuration :

# 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 ]
            

Use a draggable list instead of up/down buttons

In order to use a draggable list instead of up/down buttons, change the template in the move action to 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
                    ),
                ),
            ))
        ;
    }

Also include the JavaScript needed for this to work, in your theme.yml file, add these two lines:

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

Adding the JavaScript and the template, will give you the possibility to drag items in a tablelist. In case you need it, this plugin fires to jQuery events when dragging is done on the $(document) element, so if you want to add custom notification, that is possible. Also, when dragging the <body> gets an is-dragging class. This class is removed when you stop dragging. This could by quite handy if you have some custom js/css.

pixSortableBehaviorBundle.success
pixSortableBehaviorBundle.error

Disable top and bottom buttons

<?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,
                    ),
                ),
            ))
        ;
    }

fork-pix-digital-pix-sortable-behavior-bundle's People

Contributors

1ed avatar aitboudad avatar benjamin-hubert avatar bordeux avatar ceesvanegmond avatar jordisala1991 avatar lexxpavlov avatar nicolasricci avatar nilov avatar oskarstark avatar sc0rp10 avatar siciarek avatar tatai avatar themao avatar tofandel avatar trasher avatar vbartusevicius avatar vvh-empora avatar vviippola avatar zeliard91 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.