Skip to content
Icon

WARNING You're browsing the documentation for an old version of LARAVEL-DATATABLES. Consider upgrading your project to laravel-datatables 10.0.

Custom Actions

You can enable custom actions on your buttons, as follows:

Update UsersDataTable class and overload the actions property. Here we are disabling the csv and pdf action (so they cannot be fired by hijacking the request) and enabling a myCustomAction.

namespace App\DataTables;
 
use App\User;
use Yajra\Datatables\Services\DataTable;
 
class UsersDataTable extends DataTable
{
protected $actions = ['print', 'excel', 'myCustomAction'];
 
public function html()
{
return $this->builder()
->columns($this->getColumns())
->parameters([
'dom' => 'Bfrtip',
'buttons' => ['print', 'excel', 'myCustomAction'],
]);
}
 
public function myCustomAction()
{
//...your code here.
}
 
}

Take a look at Yajra\Datatables\Services\DataTable to see how to fetch and manipulate the data (functions excel, csv, pdf).