-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display a list of associations as a table #4126
Comments
In the meantime, you can do the following, for example:
And then create a twig file:
|
In own project needed something similar, but I needed it in many places and to avoid boilerplate I have chosen the way to create field that can show table with records from another controller inside of detail page of current controller. Here is gist to this implementation: https://gist.github.com/daffoxdev/eff74f0606bb4889d270756fec15e4b0 You can use it as a base for you own project. It's pretty universal, but maybe you will want to upgrade something for your version. Very sad that EasyAdmin uses:
For sure you will find some strange decisions on my implementation, you are welcome to give advice. Cause I'm very new in the EasyAdmin and some critical points could be missed in code. <?php
namespace App\Controller\Admin;
use App\Controller\Admin\AbstractAdminCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use App\Entity\User;
/**
* example of usage
*/
class UserController extends AbstractAdminCrudController
{
public static function getEntityFqcn(): string
{
return User::class;
}
public function configureFields(string $pageName): iterable
{
$adminContext = $this->adminContextProvider->getContext();
$userId = $adminContext->getEntity()->getPrimaryKeyValue();
$field = [
$this->newField('id'),
$this->newField('loginName'),
$this->newField('name'),
];
if ($this->isDetailPage($pageName)) {
$fields[] = FormField::addPanel('User activity')
->onlyOnDetail();
$fileds[] = $this->createUserActivityListField($userId)
->onlyOnDetail();
}
return $fields;
}
private function createUserActivityListField(int $userId): ControllerIndexField
{
return ControllerIndexField::new('user_activity_list')
->setControllerFqcn(UserActivityController::class)
->setFilter('user_id', $userId)
;
}
} Here is screenshot that abstractly shows how it will look like. Such block can be how many you wants for any controller. |
@nschmoyer why this doesn't work in edit action? |
Closing as a duplicate of #3352. |
if you only need a comma separated list you can use
|
Hi, |
Thank you very much for that example that helps lot !!!! I tried to display it in the list view changing : ea.crud.currentAction == 'detail' by ea.crud.currentAction == 'list' but it doesn't work. How we can customize the field in the list view ? |
Why do you want to add it in |
Thank you very much for your answer ! |
Instead of outputting the count of the relations or a comma-separated string if there's a
__toString
method implemented on the related class, it'd be nice to be able to show the relations as a row of cells, using, if necessary a CrudController to display what fields to show rather than have to define a custom template for each use.e.g.
which would output a nice table with one row for each product, where the fields to be displayed could be defined somewhere, presumably in the ProductCrudController here.
The text was updated successfully, but these errors were encountered: