DataTable Buttons - Export
This guide covers the export buttons available in the main DataTables package. For queue-based exports with Livewire, see the Export Usage guide.
Note: These buttons use client-side or server-side export functionality with yajra/DataTables Buttons plugin. For large datasets, consider using the Queue Export Package instead.
Export Button Group
Enable the complete export button group (Excel, CSV, and PDF buttons) with a single setting:
namespace App\DataTables; use App\Models\User;use Yajra\DataTables\Html\Button;use Yajra\DataTables\Services\DataTable; class UsersDataTable extends DataTable{ public function html() { return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('export'), ]); }}
Individual Export Buttons
Export as Excel
Enable only the Excel export button:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('excel'), ]);}
Export as CSV
Enable only the CSV export button:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('csv'), ]);}
Export as PDF
Enable only the PDF export button:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('pdf'), ]);}
POST Method Export
For large datasets or when using Internet Explorer, use POST method exports to avoid URL length limitations:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('postExcel'), Button::make('postCsv'), Button::make('postPdf'), ]);}
Required Route Setup
Add a POST route for the export endpoint in your routes file:
use App\Http\Controllers\DataTableController; // GET route for initial page loadRoute::resource('sample', DataTableController::class); // POST route for export functionalityRoute::post('sample/export', [DataTableController::class, 'index']) ->name('sample.export');
Available Button Options
| Button | Description |
|---|---|
export |
Export button group (Excel, CSV, PDF) |
excel |
Export to Excel format |
csv |
Export to CSV format |
pdf |
Export to PDF format |
postExcel |
Export to Excel using POST |
postCsv |
Export to CSV using POST |
postPdf |
Export to PDF using POST |
Utility Buttons
Print Button
Enable print preview functionality:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('print'), ]);}
Reset Button
Reset the table to its original state:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('reset'), ]);}
Reload Button
Reload the table data without resetting filters:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('reload'), ]);}
Complete Button Configuration Example
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('export'), Button::make('print'), Button::make('reset'), Button::make('reload'), ]);}
Buttons Extension Configuration
For advanced button customization, use the fluent buttons method with extended configuration:
public function html(){ return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('collection') ->text('<i class="fa fa-download"></i> Export') ->buttons([ Button::make('excel') ->text('Export to Excel') ->title('Users Report'), Button::make('csv') ->text('Export to CSV'), Button::make('pdf') ->text('Export to PDF') ->orientation('landscape'), ]), Button::make('print'), Button::make('reset'), Button::make('reload'), ]);}
Comparison: Buttons vs Queue Export
| Feature | Buttons Export | Queue Export |
|---|---|---|
| Dataset size | Small to medium | Large |
| Processing | Synchronous | Asynchronous |
| Timeout risk | High for large data | None |
| User experience | Immediate download | Background job + polling |
| Server load | High during export | Distributed over time |
| Setup complexity | Simple | Requires queue setup |
Related Documentation
- Export Installation - Queue export package setup
- Export Usage - Queue export usage
- Export Options - Customize export formatting
- Export Columns - Configure export columns