bbit/data-grid-bundle

symfony DataGridBundle

Installs: 1 141

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.2.2 2017-05-11 11:14 UTC

This package is not auto-updated.

Last update: 2024-12-21 20:52:30 UTC


README

[READ-ONLY] SubTree Split from https://github.com/BranchBit/BranchBitBaseBundle

Step 1: Download using composer

Add in your composer.json: (use the latest stable, NOT dev-master)

{
    "require": {
        "bbit/data-grid-bundle": "1.1",
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update bbit/data-grid-bundle

Composer will install the bundle to your project's vendor/BBIT directory.

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new BBIT\DataGridBundle\BBITDataGridBundle(),
        new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
    );
}

Usage example:

Controller:

$qb = $this->getDoctrine()->getRepository('AppBundle:Entry')->createQueryBuilder('x')->andWhere('x.user = :user')->setParameter(':user', $this->getUser());


$grid = $this->get('bbit_data_grid');
$grid->setQb($qb);
$grid->setItemsPerPage(10);
$grid->addField('project', 'string', [
    'sortable' => true,
    'filterable' => true,
]);

$grid->addField('start', 'datetime', [
    'sortable' => true,
]);

$grid->addField('somename', 'custom_callback', [
'extra_callback_data' => ['foo' => 'bar']
    'callback' => function($value, $extraData = null) {
        return $value->getLoggedHours(extraData['foo']);
    },
]);

$grid->addField('actions', 'custom_template', [
    'template' => 'AppBundle:foobar:some_custom_template.html.twig'
]);

return $this->render('@App/Default/entry_list.html.twig', [
    'grid' => $grid->render()
]);

Template:

{{ grid|raw }}