EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
3.99k stars 1.01k forks source link

Allow highlight searchable fields with different names #6246

Open zorn-v opened 1 month ago

zorn-v commented 1 month ago

Imagine crud controller with following configuration

//...
    public function configureCrud(Crud $crud): Crud
    {
        return $crud
            ->setSearchFields(['child_collection.subentity.title'])
        ;
    }
//...
    public function configureFields(string $pageName): iterable
    {
        return [
            CollectionField::new('child_collection')
        ];
    }

In such case, search works fine by subnested field. Search query looks like

SELECT * FROM entity 
LEFT JOIN child_collection ON entity.id = child_collection.entity_id 
LEFT JOIN subentity ON child_collection.subentity_id = subentity.id 
WHERE (LOWER(subentity.title) LIKE ?)

BUT, search terms does not highlighted in index page, because searchable css class does not added to td

With proposed change it will be possible to do like this and all will be fine

setSearchFields([
  'child_collection' => 'child_collection.subentity.title',
  'some_other_field',
])
zorn-v commented 1 month ago

Also it will be possible to highlight "unmapped" field combined from other fields like

setSearchFields([
  'customer.full_name' => 'customer.surname',
  'customer.name',
  'customer.patronymic',
])
zorn-v commented 1 month ago

Just realized that you can simply manually add searchable css class to field via addCssClass :smile: