Skip to content

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