Skip to content

Zhortein/datatable-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

489 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zhortein Datatable Bundle

A Symfony 8+ bundle for Bootstrap-first business datatables driven by PHP definitions.

Status

Stable 1.x. The documented public API follows Semantic Versioning and is covered by the compatibility policy.

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.
  • 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 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

The bundle does not currently provide a Symfony Flex recipe. The host application must:

  • register ZhorteinDatatableBundle in config/bundles.php;
  • import @ZhorteinDatatableBundle/config/routes.php;
  • enable @zhortein/datatable-bundle/datatable in assets/controllers.json;
  • install and import Bootstrap 5 and Bootstrap Icons;
  • render the AssetMapper app entrypoint 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

License

MIT

About

A Symfony 8+ bundle for Bootstrap-first business datatables driven by PHP definitions, Twig rendering and Stimulus Ajax updates.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages