Skip to content

Latest commit

 

History

History
218 lines (169 loc) · 4.53 KB

buttons-export.md

File metadata and controls

218 lines (169 loc) · 4.53 KB

DataTable Buttons

Export Button Group

To enable export button group, set export on the buttons array. Export button group includes excel, csv and pdf button.

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'],
                    ]);
    }
...

Export as Excel

To enable exporting to excel, set excel on the buttons array.

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' => ['excel'],
                    ]);
    }
...

Export as CSV

To enable exporting to csv, set csv on the buttons array.

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' => ['csv'],
                    ]);
    }
...

Export as PDF

To enable exporting to pdf, set pdf on the buttons array.

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' => ['pdf'],
                    ]);
    }
...

Export as Excel, CSV, and PDF using POST method

To enable exporting to excel, csv, and pdf using POST method set the following on the buttons array. This is recommended if you have a long query and if you are using IE browsers.

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' => ['postExcel', 'postCsv', 'postPdf'],
                    ]);
    }
...

And also add this code to your routes.php file.

    Route::resource('sample', 'SampleController@index');
    Route::post('sample/export', 'SampleController@index');
...

Printable Version

To enable print button, set print on the buttons array.

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' => ['print'],
                    ]);
    }
...

Reset Button

To enable reset button, set reset on the buttons array.

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' => ['reset'],
                    ]);
    }
...

Reload Button

To enable reload button, set reload on the buttons array.

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' => ['reload'],
                    ]);
    }
...