/DataGridBundle

Symfony2 Datagrid Bundle

Primary LanguageJavaScript

Getting Started With DataGridBundle

Datagrid for Symfony2 inspired by Zfdatagrid and Magento Grid but not compatible.

Compatibility: Symfony 2.x

The following documents are available:

  1. Installation
  2. Grid Configuration
  3. Annotations
  4. Multiple grids
  5. Overriding Templates

Special thanks to all contributors

  • Abhoryo
  • golovanov
  • touchdesign
  • Spea
  • nurikabe
  • print
  • and all bug reporters

Simple grid with ORM or ODM as source

// 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 to prevent multiple post requests
            return new RedirectResponse($grid->getRouteUrl());
        }
        else
        {
            // To obtain data for template simply pass in the grid instance
            return $this->render('MyProjectMyBundle::my_grid.html.twig', array('data' => $grid));
        }
    }
}

Rendering inside twig

<!-- MyProject\MyBundle\Resources\views\my_grid.html.twig -->
{{ grid(data) }}

Working preview with assets

Screenshot