Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Datatables Buttons

Laravel Datatables Buttons Laravel Package

yajra/laravel-datatables-buttons

Laravel DataTables Buttons plugin for server-side exports and printing. Adds CSV, Excel, PDF, and print support to yajra/laravel-datatables with DataTables Buttons integration. Works with Laravel 12+ and PHP 8.3+.

View on GitHub
Deep Wiki
Context7

yajra/laravel-datatables-buttons is an extension for Laravel DataTables that adds server-side support for the DataTables Buttons plugin—enabling reliable exports and printing from large, paginated datasets. It integrates cleanly with your existing DataTables setup and targets modern stacks (PHP 8.3+, Laravel 12+).

Use it to generate downloadable files and print views while keeping heavy work on the server for performance and consistency.

  • Server-side export for CSV, Excel, and PDF
  • Built-in print button handling
  • Works with jQuery DataTables 1.10.x + Buttons extension
  • Optional config/assets publishing via vendor:publish
  • Version-aligned releases for multiple Laravel major versions
Frequently asked questions about Laravel Datatables Buttons
How do I add CSV/Excel/PDF exports to an existing Laravel DataTables setup?
First, install the package via Composer: `composer require yajra/laravel-datatables-buttons:^13`. Then, publish the config and assets with `php artisan vendor:publish --tag=datatables-buttons`. Finally, configure the buttons in your DataTables initialization using the `buttons()` method, specifying the export formats you need (e.g., `buttons(['csv', 'excel', 'pdf'])`).
Does this package work with Laravel 13 or only Laravel 12?
The package supports both Laravel 12 and 13, with version 13.x explicitly designed for Laravel 13. Check the compatibility table in the README to ensure you’re using the correct version for your Laravel installation. Downgrading to version 12.x is possible if needed for Laravel 12.
Will this package slow down my application when exporting large datasets (e.g., 100K+ rows)?
No, the package is optimized for server-side processing, leveraging Laravel’s Eloquent/Query Builder to handle heavy workloads efficiently. For Excel exports, it uses OpenSpout (included), which is significantly faster than legacy libraries like FastExcel. Always test with your specific dataset size to confirm performance.
Can I customize the export filenames or add dynamic data to them?
Yes, you can customize export filenames using the `buttons()` method’s options. For dynamic data, use the `buttons()` callback to modify the filename or add custom logic. For example: `buttons(['csv' => ['filename' => 'custom-export-'.date('Y-m-d')]]).` You can also extend the package via macros for advanced use cases.
How do I secure exports to ensure users only access their own data?
Use Laravel’s built-in authorization (Policies, Gates) or DataTables’ `drawCallback` to filter data dynamically. For example, restrict exports to logged-in users by checking permissions in the query builder before processing. You can also use middleware to validate export requests before they reach the DataTables handler.
Is there a way to use this package with React or Vue without jQuery conflicts?
Yes, but you’ll need to wrap the DataTables initialization in a component that isolates jQuery. For React/Vue, use libraries like `alpinejs-datatables` or manually initialize DataTables in a lifecycle hook. Avoid global jQuery usage by scoping it to the component. Alternatively, consider using a headless DataTables wrapper for modern frameworks.
What PHP extensions are required for PDF exports, and how do I configure them?
PDF exports require either PhantomJS or WKHTMLtoPDF, which depend on PHP extensions like `dom` and `fileinfo`. Install these via your system package manager (e.g., `sudo apt-get install php-dom php-fileinfo`). For PhantomJS, ensure it’s installed globally or configure the package to use a custom path in the config file.
Can I add custom buttons (e.g., for JSON or XML exports) beyond CSV/Excel/PDF?
Yes, the package supports custom buttons via the `buttons()` method. For unsupported formats like JSON or XML, you can extend the package by creating a custom button class or using the `buttons()` callback to route requests to a custom controller method. Check the documentation for examples on extending the package.
How do I handle memory issues when exporting very large datasets?
For large exports, ensure your server has sufficient memory (PHP’s `memory_limit` should be increased temporarily). Use OpenSpout’s streaming capabilities for Excel exports, which minimizes memory usage. For PDFs, consider breaking exports into chunks or using a queue system (e.g., Laravel Queues) to process exports asynchronously.
What are the alternatives to this package for Laravel DataTables exports?
Alternatives include manually implementing server-side exports using Laravel’s built-in tools (e.g., Excel libraries like Maatwebsite/Laravel-Excel or Spatie/Laravel-DataExport) or client-side solutions like DataTables’ client-side export (less efficient for large datasets). However, `yajra/laravel-datatables-buttons` is the most seamless option for server-side exports integrated directly with DataTables.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport