https://github.com/kibatic/datagrid-bundle
Datagrid bundle for Symfony
https://github.com/kibatic/datagrid-bundle
php symfony
Last synced: 16 days ago
JSON representation
Datagrid bundle for Symfony
- Host: GitHub
- URL: https://github.com/kibatic/datagrid-bundle
- Owner: kibatic
- License: mit
- Created: 2022-05-25T12:09:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T15:42:30.000Z (3 months ago)
- Last Synced: 2025-06-13T22:54:27.414Z (19 days ago)
- Topics: php, symfony
- Language: PHP
- Homepage:
- Size: 130 KB
- Stars: 13
- Watchers: 4
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Kibatic Datagrid Bundle
=======================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
```bash
composer require kibatic/datagrid-bundle
```Add this to your `assets/controllers.json` :
```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
### 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
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 :
```twig
{% extends 'base.html.twig' %}{% block body %}
Project list
{% endblock %}
```Or a more classic twig approach :
```twig
{% extends 'base.html.twig' %}{% block body %}
Project list
{% include grid.theme ~ '/datagrid.html.twig' %}
{% endblock %}
```Documentation
-------------You can find a more advanced example on [how to generate your datagrid](docs/advanced-example.md).
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](docs/advanced-example.md).
Requirements
------------- Symfony 6
- PHP 8.2
- Doctrine ORMRoadmap
-------- Adding a Flex recipe