yajra / laravel-datatables-export
Laravel DataTables Queued Export Plugin.
Fund package maintenance!
yajra
Installs: 537 873
Dependents: 1
Suggesters: 3
Security: 0
Stars: 30
Watchers: 5
Forks: 18
Open Issues: 2
Requires
- php: ^8.2
- ext-json: *
- livewire/livewire: ^2.11.2|^3.5.6
- openspout/openspout: ^4.24.5
- phpoffice/phpspreadsheet: 2.3.0
- yajra/laravel-datatables-buttons: ^11.0
Requires (Dev)
- larastan/larastan: ^2.9.8
- laravel/pint: ^1.17.2
- orchestra/testbench: ^9.4.0
- pestphp/pest: ^2.35.1
- pestphp/pest-plugin-laravel: ^2.4
- rector/rector: ^1.2.4
- dev-master / 11.x-dev
- v11.3.0
- v11.2.0
- v11.1.1
- v11.1.0
- v11.0.1
- v11.0.0
- 10.x-dev
- v10.1.1
- v10.1.0
- v10.0.0
- 1.x-dev
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- 0.x-dev
- v0.14.1
- v0.14.0
- 0.13.x-dev
- v0.13.0
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.0
- v0.9.0
- v0.8.0
- v0.7.1
- v0.7.0
- v0.6.1
- v0.6.0
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
- dev-patch-url
- dev-spout
This package is auto-updated.
Last update: 2024-11-09 13:38:58 UTC
README
This package is a plugin of Laravel DataTables for handling server-side exporting using Queue, OpenSpout and Livewire.
Requirements
Documentations
Laravel Version Compatibility
Quick Installation
composer require yajra/laravel-datatables-export:^11.0
The package also requires batch job:
php artisan queue:batches-table php artisan migrate
Service Provider (Optional since Laravel 5.5+)
Yajra\DataTables\ExportServiceProvider::class
Configuration and Assets (Optional)
$ php artisan vendor:publish --tag=datatables-export --force
Usage
- Add the export-button livewire component on your view file that uses dataTable class.
<livewire:export-button :table-id="$dataTable->getTableId()"/>
- On your
DataTable
class, useWithExportQueue
use Yajra\DataTables\WithExportQueue; class PermissionsDataTable extends DataTable { use WithExportQueue; ... }
- Run your queue worker. Ex:
php artisan queue:work
Purging exported files
On app\Console\Kernel.php
, register the purge command
$schedule->command('datatables:purge-export')->weekly();
Export Filename
You can set the export filename by setting the property.
<livewire:export-button :table-id="$dataTable->getTableId()" filename="my-table.xlsx"/> <livewire:export-button :table-id="$dataTable->getTableId()" filename="my-table.csv"/> <livewire:export-button :table-id="$dataTable->getTableId()" :filename="$filename"/>
Export Button Name
You can set the export button name by setting the buttonName
property.
<!-- Examples demonstrating how to customize the button name for different scenarios --> <livewire:export-button :table-id="$dataTable->getTableId()" type="xlsx" buttonName="Export Excel"/> <livewire:export-button :table-id="$dataTable->getTableId()" type="csv" buttonName="Export CSV"/>
Export Type
You can set the export type by setting the property to csv
or xlsx
. Default value is xlsx
.
<livewire:export-button :table-id="$dataTable->getTableId()" type="xlsx"/> <livewire:export-button :table-id="$dataTable->getTableId()" type="csv"/>
Set Excel Sheet Name
Option 1: You can set the Excel sheet name by setting the property.
<livewire:export-button :table-id="$dataTable->getTableId()" sheet-name="Monthly Report"/>
Option 2: You can also set the Excel sheet name by overwriting the method.
protected function sheetName() : string { return "Yearly Report"; }
Formatting Columns
You can format the column by setting it via Column definition on you DataTable service class.
Column::make('mobile')->exportFormat('00000000000'),
The format above will treat mobile numbers as text with leading zeroes.
Numeric Fields Formatting
The package will auto-detect numeric fields and can be used with custom formats.
Column::make('total')->exportFormat('0.00'), Column::make('count')->exportFormat('#,##0'), Column::make('average')->exportFormat('#,##0.00'),
Date Fields Formatting
The package will auto-detect date fields when used with a valid format or is a DateTime instance.
Column::make('report_date')->exportFormat('mm/dd/yyyy'), Column::make('created_at'), Column::make('updated_at')->exportFormat(NumberFormat::FORMAT_DATE_DATETIME),
Valid Date Formats
Valid date formats can be adjusted on datatables-export.php
config file.
'date_formats' => [ 'mm/dd/yyyy', NumberFormat::FORMAT_DATE_DATETIME, NumberFormat::FORMAT_DATE_YYYYMMDD, NumberFormat::FORMAT_DATE_XLSX22, NumberFormat::FORMAT_DATE_DDMMYYYY, NumberFormat::FORMAT_DATE_DMMINUS, NumberFormat::FORMAT_DATE_DMYMINUS, NumberFormat::FORMAT_DATE_DMYSLASH, NumberFormat::FORMAT_DATE_MYMINUS, NumberFormat::FORMAT_DATE_TIME1, NumberFormat::FORMAT_DATE_TIME2, NumberFormat::FORMAT_DATE_TIME3, NumberFormat::FORMAT_DATE_TIME4, NumberFormat::FORMAT_DATE_TIME5, NumberFormat::FORMAT_DATE_TIME6, NumberFormat::FORMAT_DATE_TIME7, NumberFormat::FORMAT_DATE_XLSX14, NumberFormat::FORMAT_DATE_XLSX15, NumberFormat::FORMAT_DATE_XLSX16, NumberFormat::FORMAT_DATE_XLSX17, NumberFormat::FORMAT_DATE_YYYYMMDD2, NumberFormat::FORMAT_DATE_YYYYMMDDSLASH, ]
Force Numeric Field As Text Format
Option to force auto-detected numeric value as text format.
Column::make('id')->exportFormat('@'), Column::make('id')->exportFormat(NumberFormat::FORMAT_GENERAL), Column::make('id')->exportFormat(NumberFormat::FORMAT_TEXT),
Auto Download
Option to automatically download the exported file.
<livewire:export-button :table-id="$dataTable->getTableId()" filename="my-table.xlsx" auto-download="true"/>
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email aqangeles@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.