Datagrid for Symfony2 highly inspired by Zfdatagrid and Magento Grid but not compatible.
Compatibility: Symfony 2.0+ and will follow stable releases
Ultimately, the DataGridBundle files should be downloaded to the
vendor/bundles/Sorien/DataGridBundle
directory.
This can be done in several ways, depending on your preference. The first method is the standard Symfony2 method.
Using the vendors script
Add the following lines in your deps
file:
[DataGridBundle]
git=git://github.com/S0RIEN/DataGridBundle.git
target=bundles/Sorien/DataGridBundle
Now, run the vendors script to download the bundle:
$ php bin/vendors install
Using submodules
If you prefer instead to use git submodules, the run the following:
$ git submodule add git://github.com/S0RIEN/DataGridBundle.git vendor/bundles/Sorien/DataGridBundle
$ git submodule update --init
Add the Sorien
namespace to your autoloader:
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Sorien' => __DIR__.'/../vendor/bundles',
));
Finally, enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Sorien\DataGridBundle\SorienDataGridBundle(),
);
}
Now that you have completed the basic installation and configuration of the DataGridBundle, you are ready to learn about more advanced features and usages of the bundle.
The following documents are available:
<?php
// MyProject\MyBundle\DefaultController.php
namespace MyProject\MyBundle\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sorien\DataGridBundle\Grid\Source\Entity;
use Sorien\DataGridBundle\Grid\Source\Document;
class DefaultController extends Controller
{
public function myGridAction()
{
// Creates simple grid based on your entity (ORM)
$source = new Entity('MyProjectMyBundle:MyEntity');
// or use Document source class for ODM
$source = new Document('MyProjectMyBundle:MyDocument');
$grid = $this->get('grid');
// Mass actions, query and row manipulations are defined here
$grid->setSource($source);
// Columns, row actions are defined here
if ($grid->isReadyForRedirect())
{
// Data are stored, do redirect
return new RedirectResponse($this->generateUrl($this->getRequest()->get('_route')));
}
else
{
// To obtain data for template you need to call prepare function
return $this->render('MyProjectMyBundle::my_grid.html.twig', array('data' => $grid->prepare()));
}
}
}
?>
<!-- MyProject\MyBundle\Resources\views\my_grid.html.twig -->
{{ grid(data) }}