Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

422
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!