zhortein / datatable-bundle
A Symfony 8+ bundle for Bootstrap-first business datatables driven by PHP definitions, with Twig rendering, Stimulus Ajax refresh, Doctrine provider, actions, filters and CSV/XLSX exports.
Package info
github.com/Zhortein/datatable-bundle
Type:symfony-bundle
pkg:composer/zhortein/datatable-bundle
Requires
- php: >=8.4
- psr/cache: ^3.0
- symfony/config: ^8.0
- symfony/dependency-injection: ^8.0
- symfony/http-foundation: ^8.0
- symfony/http-kernel: ^8.0
- symfony/routing: ^8.0
- symfony/security-core: ^8.0
- symfony/security-csrf: ^8.0
- symfony/translation: ^8.0
- symfony/twig-bundle: ^8.0
- symfony/yaml: ^8.0
- twig/twig: ^3.21
Requires (Dev)
- doctrine/doctrine-bundle: ^3.2
- doctrine/orm: ^3.4.4 || ^4.0
- friendsofphp/php-cs-fixer: ^3.95
- friendsoftwig/twigcs: ^6.0
- openspout/openspout: ^5.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-doctrine: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^12.0
- symfony/doctrine-bridge: ^8.0
- symfony/event-dispatcher-contracts: ^3.6
- symfony/framework-bundle: ^8.0
- symfony/http-client: ^8.0
- symfony/translation-contracts: ^3.6
- symfony/var-dumper: ^8.0
Suggests
- ext-intl: Recommended for locale-aware datetime formatting through IntlDateFormatter.
- doctrine/doctrine-bundle: Required to use Doctrine ORM backed datatables in Symfony applications.
- doctrine/orm: Required to use Doctrine ORM backed datatables.
- openspout/openspout: Required to enable XLSX export support.
- symfony/asset-mapper: Recommended to expose the provided Stimulus controller with Symfony AssetMapper.
- symfony/cache: Recommended to provide a PSR-6 cache pool for persistent datatable preferences.
- symfony/http-client: Recommended to use the built-in Symfony adapter for HTTP/API backed datatables.
- symfony/stimulus-bundle: Recommended to integrate the provided vanilla Stimulus controller.
- symfony/ux-icons: Optional adapter for rendering datatable icons as SVG through Symfony UX Icons.
This package is auto-updated.
Last update: 2026-07-31 12:54:17 UTC
README
A Symfony 8+ bundle for Bootstrap-first business datatables driven by PHP definitions.
Status
Stable 1.x; 2.0 beta available. The stable public API follows Semantic Versioning. The 2.0 prerelease introduces the documented theme extension contract; review the migration guide before upgrading.
Requirements
- PHP: 8.4+
- Symfony: 8.0+
- Frontend: Bootstrap 5 (CSS/JS), Symfony UX Stimulus, and AssetMapper.
Features
- PHP-first Definitions: Declare your datatables as PHP classes with attributes.
- Twig Rendering: Render tables with a single Twig function:
{{ zhortein_datatable() }}. - Ajax Fragments: Seamless server-side updates using vanilla Stimulus.
- Data Providers: Native Doctrine ORM, Array and optional remote HTTP/API providers.
- Filtering: Built-in global search, toolbar/header filters, and advanced Search Builder.
- Multi-column Sorting: Ordered, accessible sorting shared by providers, URL state, saved views, and exports.
- Shareable State: Per-instance URL state with browser history and Turbo restoration.
- Named Views: Optional saved views with replaceable ownership, authorization and storage contracts.
- Persistent Preferences: Optional PSR-6-backed per-user defaults with explicit identity, safe filters and save/reset controls.
- Streaming Exports: Bounded-memory Doctrine, CSV and XLSX pipelines with explicit provider/writer capabilities.
- Guarded Exports: Server-side CSV/XLSX row limits, preflight counting and replaceable authorization.
- Asynchronous Exports: Optional owner-bound background jobs with storage-agnostic persistence and Symfony Messenger integration.
- Actions: Declarative row, global and bulk actions with CSRF-aware forms and opt-in Ajax execution.
- Exports: Server-side CSV and optional XLSX exports.
- Customization: Flexible UI/UX customization via Twig blocks and a 2.0 registry for complete external themes.
- Type Safety: Automatic Doctrine type detection and typed cell rendering.
- Rich Enums: Localized enum labels with optional badges, colors and icons, shared by filters and exports.
- Rich Cells: Complete server-side cell context and reusable computed values shared with exports.
- Hierarchical Tables: Accessible lazy child datatables with signed context, isolated state, and independent providers.
Installation Summary
Install the PHP dependencies:
composer require zhortein/datatable-bundle composer require symfony/asset-mapper symfony/asset symfony/stimulus-bundle
To evaluate the 2.0 prerelease explicitly:
composer require zhortein/datatable-bundle:^2.0@beta
The bundle does not currently provide a Symfony Flex recipe. The host application must:
- register
ZhorteinDatatableBundleinconfig/bundles.php; - import
@ZhorteinDatatableBundle/config/routes.php; - enable
@zhortein/datatable-bundle/datatableinassets/controllers.json; - install and import Bootstrap 5 and Bootstrap Icons;
- render the AssetMapper
appentrypoint in the base layout.
Add the frontend dependencies:
php bin/console importmap:require bootstrap php bin/console importmap:require bootstrap-icons/font/bootstrap-icons.min.css
Follow the Installation Guide for the exact file contents, verification commands and troubleshooting. Then use the Quick Start to create a complete working page.
Minimal Example
1. Define your Datatable
namespace App\Datatable; use App\Entity\User; use Zhortein\DatatableBundle\Attribute\AsDatatable; use Zhortein\DatatableBundle\Contract\DatatableInterface; use Zhortein\DatatableBundle\Definition\DatatableDefinition; #[AsDatatable(name: 'users')] final class UserDatatable implements DatatableInterface { public function buildDatatable(DatatableDefinition $definition): void { $definition ->setEntityClass(User::class) ->addColumn('e.id', visible: false) ->addColumn('e.email', label: 'Email') ->addColumn('e.createdAt', label: 'Created At', searchable: false, type: 'datetime') ; } }
2. Render it in Twig
{{ zhortein_datatable('users', { search: true }) }}
Documentation
- Documentation Index
- Installation
- Quick Start
- Providers Overview
- Doctrine Provider
- HTTP/API Provider
- Filters
- Advanced Filters
- Enum Presentation
- Multi-column Sorting
- URL State & Browser History
- Named Saved Views
- Actions & Security
- Security Model
- Bulk Actions & Selection
- Exports
- Asynchronous Export Jobs
- UI/UX & Controls
- Icon System
- Theming & Templates
- Cell Context & Computed Values
- Hierarchical Datatables
- Public API & Compatibility
- Frontend Test Strategy
- Roadmap
License
MIT