kreyu / data-table-bundle
Streamlines creation process of the data tables
Installs: 22 439
Dependents: 0
Suggesters: 0
Security: 0
Stars: 76
Watchers: 9
Forks: 14
Open Issues: 19
Type:symfony-bundle
Requires
- php: ^8.1
- symfony/form: ^6.0|^7.0
- symfony/framework-bundle: ^6.0|^7.0
- symfony/mime: ^6.0|^7.0
- symfony/translation: ^6.0|^7.0
- symfony/twig-bundle: ^6.0|^7.0
- symfony/validator: ^6.0|^7.0
- twig/extra-bundle: ^3.6
- twig/intl-extra: ^3.6
Requires (Dev)
- dg/bypass-finals: dev-master
- doctrine/doctrine-bundle: ^2.9
- doctrine/orm: ^2.15
- friendsofphp/php-cs-fixer: ^3.49
- kubawerlos/php-cs-fixer-custom-fixers: ^3.11
- openspout/openspout: ^4.23
- phpoffice/phpspreadsheet: ^1.28
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.4
- roave/security-advisories: dev-latest
- symfony/http-foundation: ^6.0|^7.0
- symfony/maker-bundle: ^1.48
- symfony/security-core: ^6.2|^7.0
- dev-main
- v0.25.6
- v0.25.5
- v0.25.4
- v0.25.3
- v0.25.2
- v0.25.1
- v0.25.0
- v0.24.3
- v0.24.2
- v0.24.1
- v0.24.0
- v0.23.0
- v0.22.3
- v0.22.2
- v0.22.1
- v0.22.0
- v0.21.4
- v0.21.3
- v0.21.2
- v0.21.1
- v0.21.0
- v0.20.1
- v0.20.0
- v0.19.2
- v0.19.1
- v0.19.0
- v0.18.1
- v0.18.0
- v0.17.12
- v0.17.11
- v0.17.10
- v0.17.9
- v0.17.8
- v0.17.7
- v0.17.6
- v0.17.5
- v0.17.4
- v0.17.3
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.3
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.4
- v0.15.3
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.4
- v0.14.3
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.1
- v0.13.0
- v0.12.2
- v0.12.1
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.12
- v0.10.11
- v0.10.10
- v0.10.9
- v0.10.8
- v0.10.7
- v0.10.6
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.3
- v0.9.2
- v0.9.1
- 0.9.0
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- dev-feature/column-type-tests-and-fixes
- dev-feature/built-in-event-listeners
- dev-various-bugfixes
- dev-feature/formatter-row-data
- dev-feature/adjustable-page-size
- dev-feature/array-proxy-query
- dev-Kreyu-patch-1
- dev-feature/themes-improvements
- dev-feature/url-oriented-improvements
- dev-feature/persistence-stimulus-controller
- dev-fix/traceable-data-table-factory-named
- dev-feature/theming-improvements
- dev-feature/gh-57
- dev-feature/gh-100
- dev-docs/enum-column-type-docs
- dev-feature/cleanup
- dev-bugfix/72-2
- dev-bugfix/72
- dev-feature/exporting-refactor
- dev-feature/column-rendering-unit-tests
- dev-feature/i18n-todo
This package is auto-updated.
Last update: 2024-11-23 00:57:11 UTC
README
Streamlines the creation process of the data tables in Symfony applications.
Warning
This bundle is still in development and is likely to change, or even change drastically. It is NOT production ready, and backwards compatibility is NOT guaranteed until the first stable release.
Documentation
Check out the official documentation.
Features
- Type classes for a class-based configuration, like in a Symfony Form component
- Sorting, filtering and pagination - classic triforce of the data tables
- Personalization where the user decides the order and visibility of columns
- Persistence to save applied data (e.g. filters) between requests
- Exporting with or without applied pagination, filters and personalization
- Theming of every part of the bundle using Twig
- Data source agnostic with Doctrine ORM supported out of the box
- Asynchronicity thanks to integration with Hotwire Turbo
Use cases
Imagine an application, that contains many listings - a list of products, categories, tags, clients, etc. In most cases, we're returning a list of data to the view, and rendering it directly in the Twig. Now, imagine, that the category details view should display a listing of its own products. Some time later, the client requires a way to sort and filter the tables.
This quickly becomes less and less maintainable as the system grows. With this bundle, you could define a data table for each entity, with their columns, filters, actions and exporters, each using a simple PHP class. Reusing the data tables (and its components) is as easy, as reusing the forms using the Symfony Form component.
However, if your application is using an admin panel generator, like a SonataAdminBundle or EasyAdminBundle, you definitely don't need this bundle. Those generators already cover the definition of data tables in their own way.
Sometimes applications are complex enough, that an admin generator would be either too simple, or too limiting. This is a case where this bundle shines - you can build a fully customized application, while delegating all the data table oriented work to the bundle.
Similarity to form component
Everything is designed to be friendly to a Symfony developers that used the Symfony Form component before.
Note
There are many similarities between those components - even in the source code! Thanks to that, it should be easy to work with the bundle, and contribute as well.
Credits to all the creators and contributors of the Symfony Form component, as they are the ones that came up with the idea of this type-based configuration, and this bundle only follows its principles.
Although, because Form component can be used outside a framework, and this bundle works only as a Symfony bundle, the core is simplified as much as possible.
Data tables and their components - columns, filters, actions and exporters, are defined using type classes, like a forms:
class ProductDataTableType extends AbstractDataTableType { public function buildDataTable(DataTableBuilderInterface $builder, array $options): void { $builder ->addColumn('id', NumberColumnType::class) ->addColumn('name', TextColumnType::class); $builder ->addFilter('id', NumericFilterType::class) ->addFilter('name', StringFilterType::class); $builder ->addAction('create', ButtonActionType::class) ->addRowAction('update', ButtonActionType::class) ->addBatchAction('delete', ButtonActionType::class); $builder ->addExporter('csv', CsvExporterType::class) ->addExporter('xlsx', XlsxExporterType::class); } }
Creating the data tables using those type classes may also seem very familiar:
class ProductController extends AbstractController { use DataTableFactoryAwareTrait; public function index(Request $request): Response { $dataTable = $this->createDataTable(ProductDataTableType::class, $query); $dataTable->handleRequest($request); return $this->render('product/index.html.twig', [ 'products' => $dataTable->createView(), ]) } }
Rendering the data table in Twig is as simple as executing a single function:
{# templates/product/index.html.twig #} <div class="card"> {{ data_table(products, { title: 'Products' }) }} </div>
License
The MIT License (MIT). Please see license file for more information.