search

Home  >  Q&A  >  body text

Add search bar to filter data within entity type fields in symfony6

I have a problem, I want to filter the output data in this entity type I found a solution but I should change the value of searchterm inside the script,

$searchTerm = 'ri';

$builder->add('userInput', EntityType::class, [
                'class' => User::class,
                'query_builder' => function(EntityRepository $er) use ($searchTerm) {
                    return $er->createQueryBuilder('u')
                        ->where('u.username LIKE :searchTerm')
                        ->setParameter('searchTerm', '%'.$searchTerm.'%')
                        ->orderBy('u.username', 'ASC');
                },
                'choice_label' => 'username',
                'required' => false,
            ])

I want to add bar search to this entityType to filter the data of u.username

P粉078945182P粉078945182235 days ago425

reply all(1)I'll reply

  • P粉348915572

    P粉3489155722024-04-04 14:37:05

    I found the solution, just implement Select2 in JS.

    reply
    0
  • Cancelreply