Building beautiful datagrids with TDBM 4.2 and Evolugrid 5.2

With the combined release of TDBM 4.2 and Evolugrid 5.2, building datagrids has never been easier.

Here is a quick sample.

Let's say you want to display a user list.

Now, your controller will look like this:

class UserController
{
    // ....

    /**
     * Returns the JSON list for the Evolugrid.
     *
     * @URL("users/list")
     * @Get()
     */
    public function list($offset = null, $limit = null, $sortKey = null, $sortOrder = null) : ResponseInterface
    {
        $users = $this->userDao->findAll()->withOrder($sortKey.' '.$sortOrder)->take($offset, $limit);

        $this->resultSet->setResults($users);

        $this->resultSet->setColumns([
            new SimpleColumn('Last name', 'name'));
            new SimpleColumn('First name', 'firstName'));
            new SimpleColumn('Country', 'country.label'));
            new TwigColumn('Edit', '< href="user/{{ id }}">Edit</a>')
        ]);

        return $this->resultSet->getResponse();
    }
}

Compared to the old TDBM and Evolugrid versions, you can see several changes:

  • No need to call $this->resultSet->setTotalRowsCount() anymore. Evolugrid can directly detect the total count from the result set (because the result set of TDBM implements the Porpaginas interface).
  • No need to write specific code for handling the order, thanks to the new withOrder method available on the result set. Heck, if you want an unfiltered list, you can even directly rely on the findAll method provided in the DAOs.
  • Columns can now consume directly any objects, so no need for mapping the result set to an array
  • Simple columns can access deep objects in the result set, using the dot notation. For instance, new SimpleColumn('Country', 'country.label')) can access the value using $obj->getCountry()->getLabel().

Thanks to TDBM 4.2 and Evolugrid 4.2, the amount of boilerplate code has been drastically reduced. Writing datagrids has never been easier!