Fast Excel Integration
Fast-Excel is recommended when exporting bulk records.
[!WARNING] FastExcel integration uses cursor behind the scenes thus eager loaded columns will not work on export. You MUST use join statements if you want to export related columns.
Usage
- Install
fast-excelusingcomposer require rap2hpoutre/fast-excel - Create a DataTable class
php artisan datatables:make Users - Adjust
UsersDataTableas needed - Set property
$fastExcel = true
<?php// app/DataTables/UsersDataTable.php namespace App\DataTables; use Yajra\DataTables\Services\DataTable; class UsersDataTable extends DataTable{ protected bool $fastExcel = true;}
Disabling Callback
Set property $fastExcelCallback = false to disable header formatting. The exported file will be based on your query's structure:
protected bool $fastExcel = true;protected bool $fastExcelCallback = false;
Custom Callback
Override the fastExcelCallback method:
<?php// app/DataTables/UsersDataTable.php namespace App\DataTables; use Yajra\DataTables\Services\DataTable; class UsersDataTable extends DataTable{ protected bool $fastExcel = true; public function fastExcelCallback(): \Closure { return function ($row) { return [ 'Name' => $row['name'], 'Email' => $row['email'], ]; }; }}
See Also
- Fast Excel Docs - Official Fast Excel documentation
- Laravel Excel - Alternative Excel export method
- Export Options - Customize export formatting