2017 © Pedro Peláez
 

symfony-bundle data-grid-bundle

Symfony DataGridBundle

image

lososoid/data-grid-bundle

Symfony DataGridBundle

  • Wednesday, September 13, 2017
  • by lososoid
  • Repository
  • 0 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 26 Forks
  • 0 Open issues
  • 37 Versions
  • 38 % Grown

The README.md

KitpagesDataGridBundle

Build Status, (*1)

SensioLabsInsight, (*2)

This Symfony2 Bundle is a simple datagrid bundle. It aims to be easy to use and extensible., (*3)

Warning version 2

Version 2 is here. You can switch to branch 1.x (or tags 1.x) if you want to stay on legacy version. There are BC Breaks between version 1 and version 2., (*4)

Actual state

  • v1.x is stable, production ready
  • v2.x is stable and production ready
    • v2.5.x is following version 2.5.x of doctrine
    • v2.4.x is following version 2.4.x of doctrine

Features

  • Display a Data Grid from a Doctrine 2 Query Builder
  • Automatic filter
  • Sorting on columns
  • Easy to configure
  • Easy to extend
  • Documented (in this readme for basics and in Resources/doc for advanced topics)
  • Paginator can be used as a standalone component
  • Change of DataGrid behaviour with events
  • Change of DataGrid presentation with twig embeds

System Requirement

  • jQuery has to be present on your pages
  • version 1.8+ of twig is mandatory (use of twig embeds)

Documentation

The documentation is in this README and in Resources/doc, (*5)

Installation

You need to add the following lines in your deps :, (*6)

Add KitpagesChainBundle in your composer.json, (*7)

{
    "require": {
        "kitpages/data-grid-bundle": "~2.4" // Use ~2.5 if you use doctrine >= 2.5
    }
}

Now tell composer to download the bundle by running the step:, (*8)

``` bash $ php composer.phar update kitpages/data-grid-bundle, (*9)


AppKernel.php ``` php $bundles = array( ... new Kitpages\DataGridBundle\KitpagesDataGridBundle(), );

Configuration in config.yml

These values are default values. You can skip the configuration if it is ok for you., (*10)

kitpages_data_grid:
    grid:
        default_twig: KitpagesDataGridBundle:Grid:grid.html.twig
    paginator:
        default_twig: KitpagesDataGridBundle:Paginator:paginator.html.twig
        item_count_in_page: 50
        visible_page_count_in_paginator: 5

Note you can use the followin configuration in order to user Bootstrap 3 :, (*11)

kitpages_data_grid:
    grid:
        default_twig: KitpagesDataGridBundle:Grid:bootstrap3-grid.html.twig
    paginator:
        default_twig: KitpagesDataGridBundle:Paginator:bootstrap3-paginator.html.twig

Simple Usage example

In the controller

use Kitpages\DataGridBundle\Grid\GridConfig;
use Kitpages\DataGridBundle\Grid\Field;
use Symfony\Component\HttpFoundation\Request;

class ContactController
{
    public function productListAction(Request $request)
    {
        // create query builder
        $repository = $this->getDoctrine()->getRepository('AcmeStoreBundle:Product');
        $queryBuilder = $repository->createQueryBuilder('item')
            ->where('item.price > :price')
            ->setParameter('price', '19.90')
        ;

        $gridConfig = new GridConfig();
        $gridConfig
            ->setQueryBuilder($queryBuilder)
            ->setCountFieldName('item.id')
            ->addField('item.id')
            ->addField('item.slug', array('filterable' => true))
            ->addField('item.updatedAt', array(
                'sortable' => true,
                'formatValueCallback' => function($value) { return $value->format('Y/m/d'); }
            ))
        ;

        $gridManager = $this->get('kitpages_data_grid.grid_manager');
        $grid = $gridManager->getGrid($gridConfig, $request);

        return $this->render('AppSiteBundle:Default:productList.html.twig', array(
            'grid' => $grid
        ));
    }
}

Twig associated

In your twig you just have to put this code to display the grid you configured., (*12)

{% embed kitpages_data_grid.grid.default_twig with {'grid': grid} %}
{% endembed %}

More advanced usage

In the controller

same controller than before, (*13)

Twig associated

If you want to add a column on the right of the table, you can put this code in your twig., (*14)

{% embed kitpages_data_grid.grid.default_twig with {'grid': grid} %}

    {% block kit_grid_thead_column %}
        <th>Action</th>
    {% endblock %}

    {% block kit_grid_tbody_column %}
        <td><a href="{{ path ("my_route", {"id": item.id}) }}">Edit</a></td>
    {% endblock %}

{% endembed %}

More advanced usage

In the controller

use Kitpages\DataGridBundle\Grid\GridConfig;
use Kitpages\DataGridBundle\Grid\Field;
use Symfony\Component\HttpFoundation\Request;

class AdminController extends Controller
{

    public function listAction(Request $request, $state)
    {
        // create query builder
        $em = $this->get('doctrine')->getEntityManager();
        $queryBuilder = $em->createQueryBuilder()
            ->select('m, e, c')
            ->from('KitappMissionBundle:Mission', 'm')
            ->leftJoin('m.employee', 'e')
            ->leftJoin('m.client', 'c')
            ->where('m.state = :state')
            ->add('orderBy', 'm.updatedAt DESC')
            ->setParameter('state', $state)
        ;

        $gridConfig = new GridConfig();
        $gridConfig
            ->setQueryBuilder($queryBuilder)
            ->setCountFieldName("m.id");
            ->addField('m.title', array('label' => 'title', 'filterable' => true))
            ->addField('m.country', array('filterable' => true))
            ->addField('c.corporation', array('filterable' => true))
            ->addField('e.lastname', array('filterable' => true))
            ->addField('e.email', array('filterable' => true))
        ;

        $gridManager = $this->get('kitpages_data_grid.grid_manager');
        $grid = $gridManager->getGrid($gridConfig, $request);

        return $this->render('KitappMissionBundle:Admin:list.html.twig', array(
            'grid' => $grid
        ));
    }
}

Twig associated

same Twig than before, (*15)

Field "as"

For request like, (*16)

$queryBuilder->select("item, item.id * 3 as foo");

You can display the foo field with, (*17)

$gridConfig->addField("item.id");
$gridConfig->addField("foo");

Events

You can modify the way this bundle works by listening events and modify some objects injected in the $event., (*18)

see the event documentation in Resources/doc/30-Events.md, (*19)

Reference guide

Add a field in the gridConfig

when you add a field, you can set these parameters :, (*20)

$gridConfig->addField('slug', array(
    'label' => 'Mon slug',
    'sortable' => false,
    'visible' => true,
    'filterable' => true,
    'translatable' => true,
    'formatValueCallback' => function($value) { return strtoupper($value); },
    'autoEscape' => true,
    'category' => null, // only used by you for checking this value in your events if you want to...
    'nullIfNotExists' => false, // for leftJoin, if value is not defined, this can return null instead of an exception
));

What can you personalize in your twig template

With the embed system of twig 1.8 and more, you can override some parts of the default rendering (see example in the "More advanced usage" paragraph)., (*21)

You can consult the base twig template here to see what you can personalize. https://github.com/kitpages/KitpagesDataGridBundle/blob/master/Resources/views/Grid/grid.html.twig, (*22)

The Versions

03/07 2014

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

MIT

The Requires

 

The Development Requires

filter paginator datagrid sort

03/07 2014

v1.11.0

1.11.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

MIT

The Requires

 

The Development Requires

filter paginator datagrid sort

12/06 2013

v1.10.0

1.10.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

04/06 2013

v1.9.0

1.9.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

23/05 2013

v1.8.0

1.8.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

22/05 2013

v1.7.0

1.7.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

02/05 2013

v1.6.1

1.6.1.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

09/04 2013

v1.6.0

1.6.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

09/04 2013

v1.5.0

1.5.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

12/03 2013

v1.4.0

1.4.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

The Development Requires

filter paginator datagrid sort

28/08 2012

v1.3.0

1.3.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

filter paginator datagrid sort

09/07 2012

v1.2.0

1.2.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

filter paginator datagrid sort

23/05 2012

v1.1.1

1.1.1.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

filter paginator datagrid sort

23/05 2012

v1.1.0

1.1.0.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

filter paginator datagrid sort

21/05 2012

v1.0.1

1.0.1.0 https://github.com/kitpages/KitpagesDataGridBundle

Symfony DataGridBundle

  Sources   Download

BSD

The Requires

 

filter paginator datagrid sort