Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

423
Vistas
How to implement an asynchronous request in EasyAdmin (Symfony)

I need a button that will generate a report in the background, for this I need to use ajax. I implemented a button template and a method to be called on this button, the button is visible in all rows, but it is called only on the first row and many at once (by clicking on the first row, the method is called as many times as there are rows). And it is necessary that it was called for each person separately. Those. by clicking on line 5, the button should fire and pass user_id = 5. Can you please tell me how to add a button to each row correctly and pass data to the controller?

easy_admin:
    entities:
        User:
            class: App\Entities\User
            label: User list
            list:
                fields:
                    - id
                    - { property: name, type: text }
                    - { property: generate, type: button, template: 'generate_report.html.twig' }  // Here I need to somehow convey user_id

Template

{% block generate_report %}
    <input type="button" value="Go" id="generate">

    <script>
        $(function () {
            $('#generate').on('click', function (e) {
                let userId = ? // user_id should be here

                $.ajax({
                    url: "{{ path('generate.report') }}",
                    type: "POST",
                    data: {
                        userId: userId
                    },
                    success: function () {
                        console.log("success")
                    },
                    error: function () {
                        console.log("error")
                    }
                });
            });
        });
    </script>

{% endblock %}

Controller

/**
* @Route(methods={"POST"}, name="generate.report")
*/
public function generateReport(): Response
{
    return $this->json(["success"]);
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda