Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmadbadpey's avatar

add Export Button Group to yajra datatable laravel package

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.

0 likes
4 replies
developer7039's avatar

I have the same problem. I event don't know how to implement it. please someone help.

Urja's avatar

You have to define where the button should be rendered. look at the datatables button document https://datatables.net/reference/option/dom. The "B" in the dom parameter is the location of the buttons

 ->parameters([
       'dom'          => 'Bfrtip',
       'buttons'      => ['export'],
 ]);

Please or to participate in this conversation.