alp-develop/laravel-livewire-tables
Reactive Livewire data tables for Laravel—search, sort, filter, paginate, export, and bulk actions with zero JavaScript. Supports Laravel 10–13, Livewire 3–4, PHP 8.1+, Tailwind or Bootstrap 4/5, plus dark mode and configurable themes.
The HasExport trait provides automatic CSV export from visible columns.
The simplest way to add CSV export is as a bulk action:
public function bulkActions(): array
{
return [
'exportCsvAuto' => 'Export CSV',
];
}
No additional code needed. The export:
resolveValue()blade, action, and image column typespublic function configure(): void
{
$this->setExportFilename('users'); // Default: 'export'
$this->setExportChunkSize(1000); // Default: 500
}
The filename is suffixed with the current date: users-2024-12-15.csv
Call exportCsvAuto() from any method (not just bulk actions):
public function downloadReport(): StreamedResponse
{
return $this->exportCsvAuto();
}
When rows are bulk-selected, exportCsvAuto() exports only those rows. Otherwise it exports the full filtered/searched query.
The export uses the model's actual primary key (getKeyName()), so UUIDs and custom primary keys work correctly.
For full control, build your own export method:
use Symfony\Component\HttpFoundation\StreamedResponse;
public function exportCustom(): StreamedResponse
{
$query = $this->buildExportQuery();
return response()->streamDownload(function () use ($query) {
$out = fopen('php://output', 'w');
fputcsv($out, ['ID', 'Name', 'Email']);
$query->chunk(500, function ($rows) use ($out) {
foreach ($rows as $row) {
fputcsv($out, [$row->id, $row->name, $row->email]);
}
});
fclose($out);
}, 'custom-export.csv', ['Content-Type' => 'text/csv']);
}
buildExportQuery() returns a Builder with search, filter, and sort pipeline applied. If bulk selection is active, it filters to selected IDs.
| Method | Description |
|---|---|
exportCsvAuto() |
Auto-generate and stream CSV download |
buildExportQuery() |
Get the query with pipeline + selection applied |
setExportFilename(string) |
Set the export file name (no extension) |
setExportChunkSize(int) |
Set the chunk size for streaming |
How can I help you explore Laravel packages today?