petkopara / PetkoparaCrudGeneratorBundle

Symfony3 CRUD generator bundle with pagination, filter, bulk actions and Twitter bootstrap 3.3.6 features.
MIT License
70 stars 17 forks source link

Adding the current/grand total on the top of the page #33

Closed romainlaisne closed 7 years ago

romainlaisne commented 7 years ago

Hi @petkopara,

I work together with @pesseyjulien, for the reference ;) We start to use your bundle in one of our project.

I thought it would be nice to have a current / grand total of the records shown on the generated page. For instance, for a list of contact, it would be "List of contacts (20/1450)".

I have done it myself on my setup, but it would be better to have it by default in the output of your generator.

Looking forward to your feedback. Thanks.

petkopara commented 7 years ago

Hi @romainlaisne can you share a snippet of you code to look for integration.

romainlaisne commented 7 years ago

Hi @petkopara,

In the controller, I get the total for the current entity:

$queryBuilder = $em->getRepository('XodmpKernelBundle:Contact')->createQueryBuilder('c');
$query = $em->getRepository('XodmpKernelBundle:Contact')->createQueryBuilder('c')->select('COUNT(c.contact_id)')
            ->getQuery();
$totalOfContacts = $query->getSingleScalarResult();

I pass this to twig:

return $this->render('XodmpKernelBundle:Contact:index.html.twig', array(
            'contacts' => $contacts,
            'pagerHtml' => $pagerHtml,
            'filterForm' => $filterForm->createView(),
            'totalOfContacts' => $totalOfContacts,

In the twig template, I show it like this:

<h3>Contact ({{ contacts|length }}/{{ totalOfContacts }})

petkopara commented 7 years ago

Added total records label in v3.0.5