kibatic / datagrid-bundle
Datagrid for Symfony
Installs: 16 207
Dependents: 0
Suggesters: 0
Security: 0
Stars: 13
Watchers: 5
Forks: 2
Open Issues: 4
Type:symfony-bundle
Requires
- php: ^8.1
- doctrine/orm: ^2.7|^3.0
- knplabs/knp-paginator-bundle: ^5.8|^6.3
- symfony/form: ^6.3|^7.0
- symfony/options-resolver: ^6.3|^7.0
- symfony/property-access: ^6.3|^7.0
- twig/extra-bundle: ^3.4
- twig/string-extra: ^3.4
- twig/twig: ^2.12.1|^3.0
Requires (Dev)
- symfony/asset-mapper: ^7.0
- dev-main
- v1.2
- v1.1.1
- v1.1
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2025-08-21 15:06:38 UTC
README
Datagrid bundle for Symfony with the following design philosophy : less magic for more flexibility.
It's not the usual one line datagrid generator, it's a more verbose one but we think it's worth it.
Features
- Your entities in a table
- Pagination
- Sortable
- Filterable
- Actions (single & batch)
- Customizable templates
- Only supports Doctrine ORM
- Theme support (Bootstrap 5 included)
Quick start
Install the bundle
composer require kibatic/datagrid-bundle
Add this to your assets/controllers.json
:
{ "controllers": { "@kibatic/datagrid-bundle": { "checker": { "enabled": true, "fetch": "eager" } } }
You'll most likely also need to enable this twig function : https://twig.symfony.com/doc/2.x/functions/template_from_string.html
It's not a hard dependency but some features shown here also requires you to install kibatic/ux-bundle
:
composer require kibatic/ux-bundle
If you want to use the default templates styles and you don't have bootstrap css loaded yet, you will need to.
If you're using AssetMapper, you can simply add this to your assets/app.js
:
import 'bootstrap/dist/css/bootstrap.min.css';
Basic usage
You can simply generate a specialized datagrid builder class skeleton using the make command :
bin/console make:datagrid
Or do everything manually, for example in your controller :
<?php namespace App\Controller; use App\Entity\Project; use App\Repository\ProjectRepository; use Kibatic\DatagridBundle\Grid\GridBuilder; use Kibatic\DatagridBundle\Grid\Template; use Kibatic\DatagridBundle\Grid\Theme; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class ProjectController extends AbstractController { #[Route('/', name: 'app_project_index', methods: ['GET'])] public function index( ProjectRepository $projectRepository, GridBuilder $gridBuilder, ): Response { // get current user $user = $this->getUser(); // create query builder filtered by current user $queryBuilder = $projectRepository->createQueryBuilder('p') ->where('p.owner = :user') ->setParameter('user', $user) ->orderBy('p.createdAt', 'DESC'); ; $grid = $gridBuilder ->initialize(queryBuilder: $queryBuilder) ->addColumn('Name', 'name') ->addColumn( 'Created at', 'createdAt', Template::DATETIME, sortable: 'createdAt' ) ->getGrid() ; return $this->render('project/index.html.twig', [ 'grid' => $grid ]); } }
Then with Symfony UX handy twig components :
{% extends 'base.html.twig' %} {% block body %} <h1>Project list</h1> <twig:datagrid :grid="grid" /> {% endblock %}
Or a more classic twig approach :
{% extends 'base.html.twig' %} {% block body %} <h1>Project list</h1> {% include grid.theme ~ '/datagrid.html.twig' %} {% endblock %}
Documentation
You can find a more advanced example on how to generate your datagrid.
If you want to customize the pagination, use the knp paginator configuration.
# config/packages/knp_paginator.yaml
knp_paginator:
page_limit: 20
If you're using a datagrid inside a live component (symfony ux), you'll need to do this.
Requirements
- Symfony 6
- PHP 8.2
- Doctrine ORM
Roadmap
- Adding a Flex recipe