EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

[FEATURE] Allow sorting of collections

Open NicoHaase opened this issue 3 years ago • 10 comments

This PR enables drag'n'drop support to order collection fields. Entities that can be sorted need a property to store the order, their collection type need such a field - and you're done :)

  1. Add a property to the entity This is as simple as:
     /**
      * @ORM\Column(type="integer")
      */
     private int $order = 0;
    
  2. Add that property to the entity type of your collection
    class OrderableType extends AbstractType {
          public function buildForm(FormBuilderInterface $builder, array $options): void
          {
              $builder->add('order', IntegerType::class);
          }
    }
    
  3. Configure the CollectionField to be orderable
    CollectionField::new('questions')
        ->setEntryType(QuestionType::class)
        ->setFormTypeOption('by_reference', true)
        ->onlyOnForms()
        ->allowDelete()
        ->setSortOrderFieldName('order')
    
  4. Optionally: you can make that order field invisible, or readonly, if you don't want others to fiddle around with that setting

If you want to try it out, you can use https://github.com/NicoHaase/ea-reproducer-4293/tree/feature/test-branch-for-3645 as a fully configured environment for this feature


Closes #3645

NicoHaase avatar May 06 '21 10:05 NicoHaase

FYI: I've just rebased the PR to cover the changes in the JS parts introduce in v3.3.0

NicoHaase avatar Jul 05 '21 10:07 NicoHaase

@javiereguiluz after having released EA v4, I'd be happy to rebase this branch. Do you see any chance that this gets merged?

NicoHaase avatar Feb 16 '22 20:02 NicoHaase

very good PR! it would be really nice if she was merged

TheTakylo avatar Apr 02 '22 15:04 TheTakylo

This would be great. EA needs all the UI help it can get!

sxsws avatar May 12 '22 11:05 sxsws

Would love to have this in EA !

grimabe avatar Jun 01 '22 21:06 grimabe

It looks very nice, @javiereguiluz did you have the time to check this?

Snowbaha avatar Jun 29 '22 09:06 Snowbaha

I would love this feature, currently I have to handle it by myself and it's a pain! @javiereguiluz any plans to merge it?

maximehardy avatar Feb 27 '23 14:02 maximehardy

@javiereguiluz It would be great to merge this one, to improve CollectionField! Do you need help? Do not hesitate to ask, I could help :wink:

welcoMattic avatar Sep 04 '23 09:09 welcoMattic

+1 for merging this feature

alex-mbp avatar Sep 05 '23 09:09 alex-mbp