yajra/laravel-datatables-html
Laravel DataTables HTML plugin for Laravel: build DataTables markup and initialization scripts in PHP, with Laravel 12+ support and Vite-friendly module output. Works with yajra/laravel-datatables to streamline table configuration and rendering.
Builder, Column, Editor), enabling decoupled table configurations per use case (e.g., admin panels, reporting tools).visibleIf) and authorization gates (e.g., addScriptIfCan) align with Laravel’s gate/policy system for multi-tenant or permission-heavy apps.Builder::useLivewire().Builder::useVite() for modern frontend pipelines.Builder::table() or Builder::toHtml().yajra/laravel-datatables (core logic), laravellux/html (form assets).$builder->columns()->editable()->buttons()) reduce cognitive load.addScript(), addScriptIf(), and getTemplate() allow deep integration with existing JS/CSS.| Risk Area | Severity | Mitigation |
|---|---|---|
| Laravel Version Lock | Medium | Package supports Laravel 8–13; ensure alignment with your LTS version (e.g., 10.x for LTS). |
| DataTables JS Conflicts | Low | Use Builder::addScriptIfCannot() to avoid duplicate script loading. |
| Livewire/Vite Edge Cases | Medium | Test DOMContentLoaded events (fixed in v12.0.2) and Vite module compatibility. |
| Performance with Complex Queries | High | Profile server-side queries; use Laravel’s query caching or database indexing. |
| Custom Styling Overrides | Low | Use Builder::setTableClass() or Column::style() for inline CSS. |
| Deprecation Risk | Low | MIT license + active maintenance (releases every 3–6 months). |
Builder::useVite().)| Laravel Component | Package Integration | Example Use Case |
|---|---|---|
| Eloquent/Query Builder | Server-side processing via DataTables::of(QueryBuilder) |
Admin panel for User model with pagination/filtering. |
| Livewire | Real-time updates with Builder::useLivewire() |
Search-as-you-type for product catalogs. |
| Vite | Asset optimization with Builder::useVite() |
Modern SPAs with Tailwind/Alpine.js. |
| Blade | Templating via Builder::table() or @datatables.table() |
Dynamic table rendering in admin dashboards. |
| Policies/Gates | Role-based column visibility with visibleIf(fn() => auth()->user()->can('view')) |
Multi-tenant SaaS with tenant-specific data. |
| API Routes | JSON export via Builder::toJson() |
Headless tables for React/Vue frontends. |
| Artisan Commands | Custom table generators with Builder::toHtml() |
CLI tools for data audits. |
columns(), buttons()).// Before (JS)
$('#users').DataTable({
processing: true,
serverSide: true,
ajax: '/api/users',
columns: [{ data: 'id' }, { data: 'name' }]
});
// After (PHP)
$builder = DataTables::of(User::query())
->addColumn('name', 'Name')
->addIndexColumn('ID')
->editColumn('active', '{{ $active ? "Yes" : "No" }}')
->toHtml();
| Compatibility Check | Status | Notes |
|---|---|---|
| Laravel 10/11/12/13 | ✅ Supported | Use ^12.x or ^13.x for latest features. |
| Livewire 2/3/4 | ✅ Supported | Test useLivewire() with Livewire 4’s event system. |
| Vite 4+ | ✅ Supported | Requires Builder::useVite() and Vite module config. |
| Bootstrap 5 | ✅ Supported | Use Paginator::useBootstrapFive() for styling. |
| Tailwind CSS | ⚠️ Partial | Custom CSS classes needed (e.g., Builder::setTableClass('table-auto')). |
| DataTables Pro | ❌ Incompatible | Open-source alternative; Pro features may require custom JS. |
| Custom DataTables Plugins | ⚠️ Possible | Use addScript() or extend via macros. |
yajra/laravel-datatables-html and yajra/laravel-datatables.AppServiceProvider:
Builder::useVite(); // For Vite
Paginator::useBootstrapFive(); // For styling
php artisan vendor:publish --tag=datatables-html
$builder = DataTables::of(User::query())
->addColumn('name', 'Name')
->editColumn('active', '{{ $active ? "Active" : "Inactive" }}')
->addButton('export', 'Export', 'post', route('users.export
How can I help you explore Laravel packages today?