Installation:
composer require avpretty/grid-bundle
Enable the bundle in config/bundles.php:
return [
// ...
AlexyAV\GridBundle\AVGridBundle::class => ['all' => true],
];
First Use Case: Display a Doctrine entity as a table in Twig:
{{ av_grid({
'data': app.doctrine.orm.entity_manager.getRepository('App\Entity\Post').findAll(),
'columns': [
{ 'name': 'id', 'label': 'ID' },
{ 'name': 'title', 'label': 'Title' },
{ 'name': 'createdAt', 'label': 'Created At', 'type': 'date' }
]
}) }}
Key Files:
config/av_grid.yml (default configuration)templates/AVGridBundle/grid.html.twig (customize via twig.config.paths)Dynamic Column Generation: Use a closure to define columns dynamically:
{{ av_grid({
'data': posts,
'columns': [
{ 'name': 'id', 'label': 'ID' },
{ 'name': 'title', 'label': 'Title' },
{
'name': 'actions',
'label': 'Actions',
'type': 'actions',
'actions': [
{ 'route': 'post_edit', 'label': 'Edit' },
{ 'route': 'post_delete', 'label': 'Delete', 'icon': 'trash' }
]
}
]
}) }}
Pagination & Sorting:
Enable via config (av_grid.yml):
default:
pagination: true
per_page: 10
sortable: true
Use in Twig:
{{ av_grid({
'data': paginatedPosts,
'pagination': {
'route': 'post_index',
'page_param': 'page'
}
}) }}
Custom Cell Rendering:
Override Twig templates or use cell_type:
{{ av_grid({
'columns': [
{
'name': 'status',
'label': 'Status',
'cell_type': 'App\\GridBundle\\Twig\\StatusCellType'
}
]
}) }}
Integration with Forms: Embed grids in forms for bulk actions:
{{ form_start(form) }}
{{ av_grid({
'data': posts,
'checkbox': true,
'checkbox_name': 'posts[]'
}) }}
{{ form_widget(form.submit) }}
{{ form_end(form) }}
Deprecated Symfony Versions:
Twig Template Overrides:
AVGridBundle:grid:base.html.twig.php bin/console cache:clear) after template changes.Performance with Large Datasets:
pagination: false).hydration_mode: LAZY in Doctrine queries for grids.Column Naming Conflicts:
name in columns matches a non-existent property, the cell renders empty.getter or setter options:
{ 'name': 'full_name', 'getter': 'getFullName' }
Enable Debug Mode:
# config/packages/av_grid.yml
debug: true
Logs column rendering issues to Symfony’s profiler.
Check Configuration:
Validate av_grid.yml for typos (e.g., per_page vs. items_per_page).
Common Errors:
name matches the entity property or getter.data is an array of objects/arrays, not null.Custom Cell Types:
Create a service tagged as av_grid.cell_type:
# config/services.yaml
services:
App\GridBundle\Cell\CustomCellType:
tags:
- { name: av_grid.cell_type, alias: 'custom' }
Event Listeners:
Hook into av_grid.pre_render to modify data before rendering:
// src/EventListener/GridListener.php
public function onPreRender(GridEvent $event) {
$event->setData(array_map(fn($item) => [...], $event->getData()));
}
Register in services.yaml:
tags:
- { name: kernel.event_listener, event: av_grid.pre_render, method: onPreRender }
Asset Management: Override CSS/JS by publishing assets:
php bin/console assets:install
Then extend grid.scss in web/css/av_grid/.
How can I help you explore Laravel packages today?