Laravel-datatables: Unexpected get json format from download excel and pdf yajra datatables

Created on 9 Oct 2020  ·  2Comments  ·  Source: yajra/laravel-datatables

Summary of problem or feature request

I've install datatable-button, all js, and all css but still get json format not download the pdf. The data can show, just cannot download the data

Code snippet of problem

Here is it my controller

return DataTables::of(Permission::query())
            ->addIndexColumn()
            ->addColumn('actions', function ($users) {
                return ActionHelper::showUpdateDeleteButton('superadmin.permissions', $users->id);
            })
            ->rawColumns(['actions'])
            ->make(true);

Here is it the js

$('#dataTable').DataTable({
                processing: true,
                serverSide: true,
                ajax: '{!! route('superadmin.permissions.datatable') !!}',
                columns: [
                    { data: 'DT_RowIndex', name: 'DT_RowIndex' , orderable: false, searchable: false},
                    { data: 'id', name: 'id' },
                    { data: 'name', name: 'name' },
                    { data: 'created_at', name: 'created_at' },
                    { data: 'updated_at', name: 'updated_at' },
                    { data: 'actions', name: 'actions' }
                ],
                dom: 'lBfrtip',
                buttons : [
                    {extend: 'colvis', postfixButtons: [ 'colvisRestore' ] },
                    {extend:'csv'},
                    {extend: 'pdf', title:'File PDF Datatables'},
                    {extend: 'excel', title: 'File Excel Datatables'},
                    {extend:'print',title: 'Print Datatables'},
                ]
            });

System details

  • Windows 10
  • PHP Version : PHP 7.3
  • Laravel Version 6.2
  • "yajra/laravel-datatables-buttons": "~4.6",
  • "yajra/laravel-datatables-oracle": "~9.0"
question

Most helpful comment

You need to use the service class of DataTable to be able to use the server-side buttons.

Quick start, use the command below:

php artisan datatables:make Permission

See https://yajrabox.com/docs/laravel-datatables/master/buttons-starter for ref.

All 2 comments

You need to use the service class of DataTable to be able to use the server-side buttons.

Quick start, use the command below:

php artisan datatables:make Permission

See https://yajrabox.com/docs/laravel-datatables/master/buttons-starter for ref.

Oke thank you. I've convert my datatable to use service class of datatable 👍🏻

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mithleshjs picture mithleshjs  ·  16Comments

ruchisheth picture ruchisheth  ·  16Comments

ZAZmaster picture ZAZmaster  ·  15Comments

MahdiPishguy picture MahdiPishguy  ·  17Comments

marioene picture marioene  ·  22Comments