diff --git a/buttons-custom.md b/buttons-custom.md new file mode 100644 index 0000000..42e7905 --- /dev/null +++ b/buttons-custom.md @@ -0,0 +1,38 @@ +# 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`. + + +```php +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`). diff --git a/documentation.md b/documentation.md index c9d3de8..941da1f 100644 --- a/documentation.md +++ b/documentation.md @@ -78,6 +78,7 @@ - [Configuration](/docs/{{package}}/{{version}}/buttons-config) - [Quick Starter](/docs/{{package}}/{{version}}/buttons-starter) - [DataTable Buttons](/docs/{{package}}/{{version}}/buttons-export) + - [Custom Actions](/docs/{{package}}/{{version}}/buttons-custom) - [Extended DataTable](/docs/{{package}}/{{version}}/buttons-extended) - [Artisan Console](/docs/{{package}}/{{version}}/buttons-console) - [Github](https://github.com/yajra/laravel-datatables-buttons)