2017 © Pedro Peláez
 

symfony-bundle grid-bundle-s3

Ajax grid for Symfony3

image

symon-white/grid-bundle-s3

Ajax grid for Symfony3

  • Thursday, October 6, 2016
  • by SymonWhite
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

pedro-teixeira/grid-bundle (Symfony3 fork)

Build Status Version Downloads License, (*1)

Ajax grid for Symfony3, (*2)

Example

, (*3)

Using Twitter Bootstrap, jQuery Bootstrap Datepicker and fake data with Faker., (*4)

Requirements

  1. Twitter Bootstrap (not mandatory)
    • If you choose to don't use Twitter Bootstrap, it'll be necessary to create your own style.
  2. jQuery Bootstrap Datepicker (not mandatory)
    • If you choose to don't use Bootstrap Datepicker, please disable the datepicker as default in the configuration, "use_datepicker".

Installation

  1. Add as a dependency in your composer file, (*5)

    "require": {
        "pedro-teixeira/grid-bundle":"dev-master"
    }
    
  2. Add to your Kernel, (*6)

    // application/ApplicationKernel.php
    public function registerBundles()
    {
        $bundles = array(
            new PedroTeixeira\Bundle\GridBundle\PedroTeixeiraGridBundle()
        );
     }
    
  3. Add to your assetics configuration, (*7)

    # application/config/config.yml
    assetic:
        bundles: [ PedroTeixeiraGridBundle ]
    
  4. Add assets to your layout, (*8)

    {% stylesheets
        '@PedroTeixeiraGridBundle/Resources/public/css/grid.css'
    %}
    <link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" />
    {% endstylesheets %}
    
    {% javascripts
        '@PedroTeixeiraGridBundle/Resources/public/js/grid.js'
    %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
    
  5. (optional) Adjust configurations, (*9)

    # application/config/config.yml
    pedro_teixeira_grid:
        defaults:
            date:
                use_datepicker:     true
                date_format:        'dd/MM/yy'
                date_time_format:   'dd/MM/yy HH:mm:ss'
            pagination:
                limit:              20
            export:
                enabled:            true
                path:               '/tmp/'
    

    The configuration "use_datepicker" will set the input type as "text" and attach a jQuery plugin "datepicker()" to the filter., (*10)

Create your grid

  1. Create the grid class, (*11)

    In your bundle, create a folder named "Grid" (or wathever namespace you want) and create your grid definition class., (*12)

    <?php
    
    namespace PedroTeixeira\Bundle\TestBundle\Grid;
    
    use PedroTeixeira\Bundle\GridBundle\Grid\GridAbstract;
    
    /**
     * Test Grid
     */
    class TestGrid extends GridAbstract
    {
        /**
         * {@inheritdoc}
         */
        public function setupGrid()
        {
            $this->addColumn('Hidden Field')
                ->setField('hidden')
                ->setIndex('r.hidden')
                ->setExportOnly(true);
    
            $this->addColumn('ID')
                ->setField('id')
                ->setIndex('r.id')
                ->getFilter()
                    ->getOperator()
                        ->setComparisonType('equal');
    
            $this->addColumn('Created At')
                ->setField('createdAt')
                ->setIndex('r.createdAt')
                ->setFilterType('date_range')
                ->setRenderType('date');
    
            $this->addColumn('Name')
                ->setField('name')
                ->setIndex('r.name');
    
            $this->addColumn('Number')
                ->setField('number')
                ->setIndex('r.number')
                ->setFilterType('number_range');
    
            $this->addColumn('Options')
                ->setField('option')
                ->setIndex('r.options')
                ->setFilterType('select')
                ->getFilter()
                    ->setOptions(array(
                        'key' => 'value'
                    ));
    
            $this->addColumn('Action')
                ->setTwig('PedroTeixeiraTestBundle:Test:gridAction.html.twig')
                ->setFilterType(false);
        }
    }
    
  2. Use the grid factory in your controller, (*13)

    <?php
    
    namespace PedroTeixeira\Bundle\TestBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
    
    use JMS\SecurityExtraBundle\Annotation\Secure;
    
    /**
     * Default controller
     */
    class DefaultController extends Controller
    {
        /**
         * @Route("/", name="test")
          * @Template()
          *
          * @return array
          */
        public function indexAction(Request $request)
        {
            /** @var \Doctrine\ORM\EntityRepository $repository */
            $repository = $this->getDoctrine()->getRepository('PedroTeixeiraTestBundle:TestEntity');
            $queryBuilder = $repository->createQueryBuilder('r');
    
            /** @var \PedroTeixeira\Bundle\TestBundle\Grid\TestGrid $grid */
            $grid = $this->get('pedroteixeira.grid')->createGrid('\PedroTeixeira\Bundle\TestBundle\Grid\TestGrid', $request);
            $grid->setQueryBuilder($queryBuilder);
    
            if ($grid->isResponseAnswer()) {
                return $grid->render();
            }
    
            return array(
                'grid'   => $grid->render()
            );
        }
    }
    
  3. Render in your template, (*14)

    ```twig {{ pedroteixeira_grid(grid) }}, (*15)


    Or if you want to render the grid's html and the grid's js separately: ```twig {{ pedroteixeira_grid_html(grid) }} ... {{ pedroteixeira_grid_js(grid) }}

Understanding

Continuous integration

To execute locally the checks that are executed on Travis:, (*16)

composer install
find ./Grid ./DependencyInjection ./Twig -name "*.php" -exec php -l {} \;
./bin/phpcs --extensions=php --standard=PSR2 ./Grid ./DependencyInjection ./Twig

The Versions

06/10 2016

dev-master

9999999-dev http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony3

  Sources   Download

MIT

The Requires

 

The Development Requires

grid datagrid

31/03 2015

v1.0.0

1.0.0.0 http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

grid datagrid

07/10 2014

v0.2.0

0.2.0.0 http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

grid datagrid

29/08 2014

v0.1.2

0.1.2.0 http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

grid datagrid

18/08 2014

v0.1.1

0.1.1.0 http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

grid datagrid

08/08 2014

v0.1.0

0.1.0.0 http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

grid datagrid

06/06 2014

v0.0.4-beta

0.0.4.0-beta http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

grid datagrid

16/04 2013

v0.0.3-beta

0.0.3.0-beta http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

grid datagrid

13/03 2013

v0.0.2-beta

0.0.2.0-beta http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

grid datagrid

11/03 2013

v0.0.1-beta

0.0.1.0-beta http://github.com/pedro-teixeira/grid-bundle

Ajax grid for Symfony2

  Sources   Download

MIT

The Requires

 

grid datagrid