mmucklo/grid-bundle
Symfony bundle to generate searchable, customizable grids from Doctrine ORM entities or MongoDB ODM documents. Renders via jQuery DataTables, jqGrid, or styled HTML tables with Bootstrap-friendly output, column customization, and easy setup for Symfony 3.4–8.0.
Installation:
composer require mmucklo/grid-bundle
For Symfony 2/3, add new \Dtc\GridBundle\DtcGridBundle() to AppKernel.php.
Enable Reflection (Symfony 4+):
Configure config/packages/dtc_grid.yaml:
dtc_grid:
reflection:
allowed_entities: ['App:User', 'App:Product'] # Replace with your entities
Annotate an Entity:
use Dtc\GridBundle\Annotation as Grid;
/**
Clear Cache:
bin/console cache:clear
bin/console cache:warmup
Access Grid:
Visit /dtc_grid/grid?class=App:User&type=datatables (replace User with your entity).
Render a searchable, sortable table for App\Entity\User:
// In a controller
$renderer = $this->get('dtc_grid.renderer.factory')->create('datatables');
$gridSource = $this->get('dtc_grid.manager.source')->get('App:User');
$renderer->bind($gridSource);
return $this->render('@DtcGrid/Page/datatables.html.twig', $renderer->getParams());
/**
* @Grid\Grid(
* actions={
* @Grid\ShowAction(),
* @Grid\DeleteAction(),
* @Grid\Action(label="Custom", onclick="alert('Hello')")
* }
* )
*/
class User { ... }
config/dtc_grid/[entity].yamlApp\User:
columns:
username: { sortable: true, searchable: true }
email: { searchable: true }
actions:
- { label: "Show", type: show, route: dtc_grid_show }
/**
* @Route("/custom-grid", name="custom_grid")
*/
public function customGrid(Request $request) {
$renderer = $this->get('dtc_grid.renderer.factory')->create('datatables');
$gridSource = $this->get('dtc_grid.manager.source')->get('App:Product');
$renderer->bind($gridSource);
return $this->render('custom_grid.html.twig', $renderer->getParams());
}
gridSource instances.renderer.{% for grid in grids %}
{{ grid.render | raw }}
{% endfor %}
/**
* @Grid\Column(
* label="Full Name",
* sortable=false,
* searchable=true,
* template="{{ entity.firstName }} {{ entity.lastName }}"
* )
*/
protected $fullName;
onclick actions to trigger modal forms.data-* attributes.@Grid\Action(
label="Edit",
onclick="openEditModal({{ entity.id }})",
buttonClass="btn-primary"
)
bin/console cache:clear
bin/console cache:warmup
dtc_grid:
reflection:
allowed_entities: ['App:CriticalEntity'] # Limit to essentials
/dtc_grid route is public.security.yaml:
access_control:
- { path: ^/dtc_grid, roles: ROLE_ADMIN }
dtc_grid:
datatables:
js:
- 'https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js'
odm_default in annotations:
/**
* @Grid\Column(odm_default="title")
*/
protected $name;
serverSide: true in DataTables config.@Grid\Column annotations.datatables type:
$renderer = $this->get('dtc_grid.renderer.factory')->create('datatables');
onclick actions fail silently.<script>
window.onload = function() {
console.log("Grid loaded. Check browser console for errors.");
};
</script>
templates/DtcGridBundle/:
{# templates/DtcGridBundle/Page/datatables.html.twig #}
{% extends "base.html.twig" %}
{% block stylesheets %}
{{ parent() }}
{{ asset('css/custom-grid.css') }}
{% endblock %}
config/packages/dtc_grid.yaml:
dtc_grid:
bootstrap:
css: 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'
\Dtc\GridBundle\Renderer\AbstractRenderer.namespace App\Grid;
use Dtc\GridBundle\Renderer\AbstractRenderer;
class CustomRenderer extends AbstractRenderer {
public function getType() { return 'custom'; }
// Override render logic
}
Register as a service:
services:
app.grid.custom_renderer:
class: App\Grid\CustomRenderer
tags: { name: dtc_grid.renderer }
gridSource to inspect columns/actions:
$gridSource = $this->get('dtc_grid.manager.source')->get('App:User');
dump($gridSource->getColumns());
{% trans with {'%column%': 'Aktionen'} %}Actions{% endtrans %}
Or extend the bundle’s translation files.How can I help you explore Laravel packages today?