ram-electronic / datatable-bundle
Reusable DataTable and Pagination bundle for Symfony applications
Package info
github.com/ram-electronic/datatable-bundle
Type:symfony-bundle
pkg:composer/ram-electronic/datatable-bundle
Requires
- php: >=8.4
- doctrine/orm: ^3.0
- symfony/form: ^7.0
- symfony/framework-bundle: ^7.0
- symfony/routing: ^7.0
- symfony/security-csrf: ^7.0
- symfony/translation: ^7.0
- symfony/translation-contracts: ^3.0
- symfony/twig-bundle: ^7.0
- symfony/ux-icons: ^2.32
- symfony/ux-live-component: ^2.0
- symfony/ux-twig-component: ^2.0
- symfony/validator: ^7.0
- tales-from-a-dev/twig-tailwind-extra: ^1.0
- twig/extra-bundle: ^3.12
- twig/html-extra: ^3.12
- twig/twig: ^3.0
Requires (Dev)
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-02 19:53:02 UTC
README
Reusable DataTable and Pagination bundle for Symfony applications: filterable, sortable, paginated table views built on Doctrine ORM, Symfony Forms, and Symfony UX Live Components.
Requirements
- PHP 8.4+
- Symfony 7.0+ (
framework-bundle,form,routing,security-csrf,translation,validator,twig-bundle) - Symfony UX
live-component,twig-component2.0+, andux-icons(for the default pagination chevrons) - Doctrine
orm3.0+ anddoctrine-bundle2.11+ - Twig 3.0+,
twig/extra-bundleandtwig/html-extra(for the defaultButton:*components' variant styling), andtales-from-a-dev/twig-tailwind-extra(for thetailwind_mergefilter used throughout the bundle's default markup)
Installation
composer require ram-electronic/datatable-bundle
If your app doesn't use Symfony Flex, register the bundle — and the Twig
extension bundles its default components depend on — manually in
config/bundles.php:
return [ // ... Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], TalesFromADev\Twig\Extra\Tailwind\Bridge\Symfony\Bundle\TalesFromADevTwigExtraTailwindBundle::class => ['all' => true], Symfony\UX\Icons\UXIconsBundle::class => ['all' => true], RamElectronic\DataTableBundle\DataTableBundle::class => ['all' => true], ];
Twig components
The bundle auto-registers every component under the
RamElectronic\DataTableBundle\Presentation\Twig\Components namespace — there
is nothing else to install or implement, FilterForm, FilterCondition, and
PaginationControl render out of the box:
-
FilterForm/FilterCondition— Live Components backing the filter UI -
PaginationControl— pagination controls -
DataTable:Table/DataTable:Pagination— generic table/nav wrappers. -
DataTable:Card,DataTable:ButtonRow,DataTable:Button:Button,DataTable:Button:Link,DataTable:Form:Input,DataTable:Pagination:Content,DataTable:Pagination:Previous,DataTable:Pagination:Next— the shadcn/ui-style primitivesFilterForm/FilterCondition/PaginationControlare built from.All of the above are named with an explicit
DataTable:prefix (rather than the bareTable/Card/Button:Button/etc. a plain#[AsTwigComponent]would produce) so they can never collide with a same-named top-level component a consuming app defines for its own, unrelated markup. -
Table:Body,Table:Cell,Table:Head,Table:Header,Table:Row,Table:ActionsCell,Table:DataCell,Table:HeadRow,Table:SortableHeader— already namespaced underTable:, so no separate prefixing is needed.
See templates/components/ for the reference markup these components render.
Customizing the default components
Every default component's look can be overridden per-file, without touching
registration, using Symfony's standard bundle-template-override mechanism:
drop a file at templates/bundles/DataTableBundle/<relative-path> in your app
— e.g. templates/bundles/DataTableBundle/components/Card.html.twig — and
Symfony will render your version instead of the bundle's default for that one
component, leaving the rest of the bundle's defaults untouched.
Pagination labels (Previous/Next and their aria-labels) live in the
bundle's own datatable translation domain (translations/datatable.*.xlf,
shipped in English and German) rather than your app's messages domain, so
they work without any translation keys of your own.
Usage
- Define your filterable columns with an
Application\ReadModel\FilterFieldRegistrysubclass built fromColumndefinitions. - Extend
Infrastructure\Repository\DoctrineTableReadModelRepositoryfor your read-model entity's repository — it provides filtering, sorting, and pagination against a DoctrineQueryBuildergiven a field-to-column mapping. - In your controller, build a
TableCriteriafrom request/form data viaPresentation\Service\TableCriteriaBuilder(which composesFilterCollectionBuilder), and pass it to your repository. - Render results with
PaginationControland the bundle'sDataTable:Table/Table:*components inside your own table markup.
Testing
composer install vendor/bin/phpunit
License
MIT, see LICENSE.