EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

CollectionTableField in addition to CollectionField

Open brunomartin opened this issue 1 year ago • 1 comments

Adding CollectionTableField to available fields

CollectionField is an amazing feature that does its job. I have a project that required to synthesize information in a table rather in widgets. This feature shall display a table with field label in table header and form widget in each cell.

Example of CollectionTableField use Following fields pays and purchases are 2 OneToMany relations of the entity of the current Quotation entity which CRUD controller would look like the following:

class QuotationCrudController extends AbstractCrudController
{
...

    public function configureFields(string $pageName): iterable
    {
...
        yield CollectionTableField::new('pays')
            ->allowAdd()
            ->allowDelete()
            ->hideOnIndex()
            ->useEntryCrudForm(PayCrudController::class)
            ;

        yield CollectionField::new('purchases')
            ->allowAdd()
            ->allowDelete()
            ->hideOnIndex()
            ->useEntryCrudForm(PurchaseCrudController::class)
            ;
...
    }
...
}

Resulting rendered form shall look like following:

image

brunomartin avatar Mar 16 '24 15:03 brunomartin

grid-collection-field.zip

This is what I came up with. It has some limitations but it works in my case, without touching EA source code. Just add the css to your CRUD and adjust the field's ->setColumns() values.

nevez avatar Jul 16 '24 08:07 nevez