Add GlavwebDatagridBundle by running this command from the terminal at the root of your Symfony project:
php composer.phar require glavweb/datagrid-bundle
To start using the bundle, register the bundle in your application's kernel class:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Glavweb\DatagridBundle\GlavwebDatagridBundle(),
// ...
);
}
This bundle was designed to just work out of the box. The only thing you have to configure in order to get this bundle up and running is a mapping.
Define data schema:
# app/config/data_schema/article.schema.yml
schema:
class: AppBundle\Entity\Article
properties:
id:
name:
slug:
body:
Define scope:
# app/config/scopes/article/short.yml
scope:
name:
Usage in a controller:
$datagridBuilder = $this->get('glavweb_datagrid.doctrine_datagrid_builder')
->setEntityClassName('AppBundle\Entity\Article')
->setAlias('t')
->setDataSchema('article.schema.yml', 'article/short.yml')
->setFirstResult(0)
->setMaxResults(2)
->setOrderings(['name' => 'ASC'])
;
// Define filters
$datagridBuilder
->addFilter('name')
;
$datagrid = $this->datagridBuilder->build(['name' => 'Article 1']);
$list = $datagrid->getList();