|
| 1 | +# DataTable Buttons |
| 2 | + |
| 3 | +<a name="export"></a> |
| 4 | +## Export Button Group |
| 5 | + |
| 6 | +To enable export button group, set `export` on the buttons array. |
| 7 | +Export button group includes `excel`, `csv` and `pdf` button. |
| 8 | + |
| 9 | +```php |
| 10 | +namespace App\DataTables; |
| 11 | + |
| 12 | +use App\User; |
| 13 | +use Yajra\Datatables\Services\DataTable; |
| 14 | + |
| 15 | +class UsersDataTable extends DataTable |
| 16 | +{ |
| 17 | + //...some default stubs deleted for simplicity. |
| 18 | + |
| 19 | + public function html() |
| 20 | + { |
| 21 | + return $this->builder() |
| 22 | + ->columns($this->getColumns()) |
| 23 | + ->parameters([ |
| 24 | + 'buttons' => ['export'], |
| 25 | + ]); |
| 26 | + } |
| 27 | +... |
| 28 | +``` |
| 29 | + |
| 30 | +<a name="excel"></a> |
| 31 | +## Export as Excel |
| 32 | + |
| 33 | +To enable exporting to excel, set `excel` on the buttons array. |
| 34 | + |
| 35 | +```php |
| 36 | +namespace App\DataTables; |
| 37 | + |
| 38 | +use App\User; |
| 39 | +use Yajra\Datatables\Services\DataTable; |
| 40 | + |
| 41 | +class UsersDataTable extends DataTable |
| 42 | +{ |
| 43 | + //...some default stubs deleted for simplicity. |
| 44 | + |
| 45 | + public function html() |
| 46 | + { |
| 47 | + return $this->builder() |
| 48 | + ->columns($this->getColumns()) |
| 49 | + ->parameters([ |
| 50 | + 'buttons' => ['excel'], |
| 51 | + ]); |
| 52 | + } |
| 53 | +... |
| 54 | +``` |
| 55 | + |
| 56 | +<a name="csv"></a> |
| 57 | +## Export as CSV |
| 58 | + |
| 59 | +To enable exporting to csv, set `csv` on the buttons array. |
| 60 | + |
| 61 | +```php |
| 62 | +namespace App\DataTables; |
| 63 | + |
| 64 | +use App\User; |
| 65 | +use Yajra\Datatables\Services\DataTable; |
| 66 | + |
| 67 | +class UsersDataTable extends DataTable |
| 68 | +{ |
| 69 | + //...some default stubs deleted for simplicity. |
| 70 | + |
| 71 | + public function html() |
| 72 | + { |
| 73 | + return $this->builder() |
| 74 | + ->columns($this->getColumns()) |
| 75 | + ->parameters([ |
| 76 | + 'buttons' => ['csv'], |
| 77 | + ]); |
| 78 | + } |
| 79 | +... |
| 80 | +``` |
| 81 | + |
| 82 | +<a name="pdf"></a> |
| 83 | +## Export as PDF |
| 84 | + |
| 85 | +To enable exporting to pdf, set `pdf` on the buttons array. |
| 86 | + |
| 87 | +```php |
| 88 | +namespace App\DataTables; |
| 89 | + |
| 90 | +use App\User; |
| 91 | +use Yajra\Datatables\Services\DataTable; |
| 92 | + |
| 93 | +class UsersDataTable extends DataTable |
| 94 | +{ |
| 95 | + //...some default stubs deleted for simplicity. |
| 96 | + |
| 97 | + public function html() |
| 98 | + { |
| 99 | + return $this->builder() |
| 100 | + ->columns($this->getColumns()) |
| 101 | + ->parameters([ |
| 102 | + 'buttons' => ['pdf'], |
| 103 | + ]); |
| 104 | + } |
| 105 | +... |
| 106 | +``` |
| 107 | + |
| 108 | +<a name="print"></a> |
| 109 | +## Printable Version |
| 110 | + |
| 111 | +To enable print button, set `print` on the buttons array. |
| 112 | + |
| 113 | +```php |
| 114 | +namespace App\DataTables; |
| 115 | + |
| 116 | +use App\User; |
| 117 | +use Yajra\Datatables\Services\DataTable; |
| 118 | + |
| 119 | +class UsersDataTable extends DataTable |
| 120 | +{ |
| 121 | + //...some default stubs deleted for simplicity. |
| 122 | + |
| 123 | + public function html() |
| 124 | + { |
| 125 | + return $this->builder() |
| 126 | + ->columns($this->getColumns()) |
| 127 | + ->parameters([ |
| 128 | + 'buttons' => ['print'], |
| 129 | + ]); |
| 130 | + } |
| 131 | +... |
| 132 | +``` |
0 commit comments