EasyAdmin, how can I add custom column to grid? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, July 28, 2023

EasyAdmin, how can I add custom column to grid?

I want to add a column not in my entity and require some custom query/subquery. For eg. I have an entity with users assigned to it, and I want a column that will show the user count, but only active users, or only users created after some date. I was trying to add a field to the query builder but then I'm getting an error related to '"id as an array". Is this even possible using Easyadmin?

For test I was trying to add any field to query builder

public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
[...]
    $queryBuilder->addSelect('1 AS userCount');
    return $queryBuilder;
}

but then i'm gettin error Cannot read property "id" from an array. Maybe you intended to write the property path as "[id]" instead. I dumped paginator from AbstractCrudController::index and saw that results now have little diffrent structure

  -results: ArrayIterator {#900 ▼
    -storage: array:10 [▼
      0 => array:2 [▼
        0 => App\Entity\Company {#916 ▶}
        "userCount" => 1
      ]
      1 => array:2 [▼
        0 => App\Entity\Company {#814 ▶}
        "userCount" => 1
      ]

Normaly you only have array of entities not array of array with entity and custom value.



source https://stackoverflow.com/questions/76782541/easyadmin-how-can-i-add-custom-column-to-grid

No comments:

Post a Comment