![]()
WARNING You're browsing the documentation for an upcoming version of Laravel DataTables. The documentation and features of this release are subject to change.
Custom Actions
You can enable custom actions on your buttons by overloading the buttons method in your DataTable class.
Creating a Custom Action
namespace App\DataTables; use App\Models\User;use Yajra\DataTables\Html\Button;use Yajra\DataTables\Services\DataTable; class UsersDataTable extends DataTable{ protected array $actions = ['print', 'excel', 'myCustomAction']; public function html() { return $this->builder() ->columns($this->getColumns()) ->layout([ 'topStart' => 'buttons', 'topEnd' => 'search', 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->buttons([ Button::make('print'), Button::make('excel'), Button::make('myCustomAction'), ]); } public function myCustomAction() { //...your code here. }}
Take a look at Yajra\DataTables\Services\DataTable to see how to fetch and manipulate data (see excel, csv, pdf methods).
See Also
- Buttons Console - Artisan commands for generating DataTables
- Buttons Export - Export button options
- Buttons Starter - Quick start guide