I am using yajra laravel datatables package version 6.0 and I want to add export button group But I do not know how can I implement that.
Suppose I have a SubscriberController
class like this :
public function newsletterDatatable (Request $request) {
$subscribers = Subscriber::select(['sub_id', 'email', 'confirmed', 'created_at']);
$datatable = app('datatables')->of($subscribers)
->orderBy('created_at', 'desc')
->addColumn('checkbox', '<input type="checkbox" name="item_id[]" value="{{$sub_id}}">');
return $datatable->make(true);
}
And in JS codes I have :
$('#allSubscribersTable').DataTable({
processing: true,
serverSide: true,
"bSort": false,
"responsive": true,
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
ajax: {
url: '{!! route('admin.newsletterDatatable') !!}'
},
columns: [
{data: 'checkbox', "width": "20px"}
]
});
As you can see I used buttons
option on DataTable initialization but when table is shown there are not any export buttons.
On the buttons-export page on Docs is said that I should add below Code But I do not know where and how to use in my controller :
namespace App\DataTables;
use App\User;
use Yajra\Datatables\Services\DataTable;
class UsersDataTable extends DataTable {
//...some default stubs deleted for simplicity.
public function html() {
return $this->builder()
->columns($this->getColumns())
->parameters([
'buttons' => ['export'],
]);
}
...
If anyone know please help me.