PHPackages                             aliocza/sortable-ui-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. aliocza/sortable-ui-bundle

ActiveSymfony-bundle[Admin Panels](/categories/admin)

aliocza/sortable-ui-bundle
==========================

Provides a way to sort your admin listing

25.1k2PHP

Since Aug 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/aliocza/SortableUiBundle)[ Packagist](https://packagist.org/packages/aliocza/sortable-ui-bundle)[ RSS](/packages/aliocza-sortable-ui-bundle/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

SortableUibundle
================

[](#sortableuibundle)

It's totally rework for a better gui.

The original 'bundle' provided by :

The original 'cookbook' proived by : [https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe\_sortable\_listing.rst](https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe_sortable_listing.rst)

In the future features :

- multi level drag and drop
- improve performance code
- comment the code
-

Configuration
-------------

[](#configuration)

```
# app/config/config.yml
aliocza_sortable_ui:
    db_driver: orm # default value : orm (orm is only supported)
    position_field:
        default: sort #default value : position
        entities:
            AppBundle/Entity/Foobar: order
            AppBundle/Entity/Baz: rang

```

Cookbook for Sonata Admin
=========================

[](#cookbook-for-sonata-admin)

Pre-requisites
--------------

[](#pre-requisites)

- you already have SonataAdmin and DoctrineORM up and running
- you already have an Entity class for which you want to implement a sortable feature. For the purpose of the example we are going to call it `Client`.
- you already have an Admin set up, in this example we will call it `ClientAdmin`
-

Bundles
-------

[](#bundles)

- install `gedmo/doctrine-extensions` bundle in your project (check `stof/doctrine-extensions-bundle` for easier integration in your project) and enable the sortable feature in your config. For how to install bundle :
- install `aliocza/sortable-ui-bundle` in your project

The recipe
----------

[](#the-recipe)

First of all we are going to add a position field in our `Client` entity.

```
    use Gedmo\Mapping\Annotation as Gedmo;
    // ...
    /**
     * @Gedmo\SortablePosition
     * @ORM\Column(name="position", type="integer")
     */
    private $position;

```

Then we need to inject the Sortable listener. If you only have the Gedmo bundle enabled, you only have to add the listener to your config.yml and skip this step.

```
services:
    gedmo.listener.sortable:
        class: Gedmo\Sortable\SortableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ "@annotation_reader" ] ]

```

In our `ClientAdmin` we are going to add a custom action in the `configureListFields` method and use the default twig template provided in the `alioczaSortableUiBundle`

```
	$listMapper
	    ->add('_action', 'actions', array(
            'actions' => array(
                'drag' => array(
                            'template' => 'AlioczaSortableUiBundle:Default:drag.html.twig'
                ),
            )
        )
    );

```

In order to add new routes for these actions we are also adding the following method and we override the template for add button

```
