You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+142-1Lines changed: 142 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -164,6 +164,21 @@ public function hide() : self;
164
164
* Hide this column based on a condition. i.e.: user has or doesn't have a role or permission. Must return a boolean, not a closure.
165
165
*/
166
166
public function hideIf($condition) : self;
167
+
168
+
/**
169
+
* This column is only included in exports and is not available to the UI
170
+
*/
171
+
public function exportOnly() : self;
172
+
173
+
/**
174
+
* This column is excluded from the export but visible to the UI unless defined otherwise with hide() or hideIf()
175
+
*/
176
+
public function excludeFromExport() : self;
177
+
178
+
/**
179
+
* If supplied, and the column is exportable, this will be the format when rendering the CSV/XLS/PDF instead of the format() function. You may have both, format() for the UI, and exportFormat() for the export only. If this method is not supplied, format() will be used and passed through strip_tags() to try to clean the output.
180
+
*/
181
+
public function exportFormat(callable $callable = null) : self;
167
182
```
168
183
169
184
### Properties
@@ -221,6 +236,13 @@ You can override any of these in your table component:
221
236
| -------- | ------- | ----- |
222
237
| $offlineIndicator | true | Whether or not to display an offline message when there is no connection |
223
238
239
+
#### Exports
240
+
241
+
| Property | Default | Usage |
242
+
| -------- | ------- | ----- |
243
+
| $exportFileName | data | The name of the downloaded file when exported |
244
+
| $exports |[]| The available options to export this table as (csv, xls, xlsx, pdf) |
245
+
224
246
#### Other
225
247
226
248
| Property | Default | Usage |
@@ -292,7 +314,120 @@ public function email($email): string
292
314
public function html($html): HtmlString
293
315
```
294
316
295
-
### Setting Options
317
+
### Exporting Data
318
+
319
+
The table component supports exporting to CSV, XLS, XLSX, and PDF.
320
+
321
+
In order to use this functionality you must install [Laravel Excel](https://laravel-excel.com) 3.1 or newer.
322
+
323
+
In order to use the PDF export functionality, you must also install either [DOMPDF](https://github.com/dompdf/dompdf) or [MPDF](https://github.com/mpdf/mpdf).
324
+
325
+
You may set the PDF export library in the config file under **pdf_library**. DOMPDF is the default.
326
+
327
+
#### What exports your table supports
328
+
329
+
By default, exporting is off. You can add a list of available export types with the $exports class property.
By default, the filename will be `data`.*type*. I.e. `data.pdf`, `data.csv`.
336
+
337
+
You can change the filename with the `$exportFileName` class property.
338
+
339
+
`public $exportFileName = 'users-table';` - *Obviously omit the file type*
340
+
341
+
#### Deciding what columns to export
342
+
343
+
You have a couple option on exporting information. By default, if not defined at all, all columns will be exported.
344
+
345
+
If you have a column that you want visible to the UI, but not to the export, you can chain on `excludeFromExport()`
346
+
347
+
If you have a column that you want visible to the export, but not to the UI, you can chain on `exportOnly()`
348
+
349
+
#### Formatting column data for export
350
+
351
+
By default, the export will attempt to render the information just as it is shown to the UI. For a normal column based attribute this is fine, but when exporting formatted columns that output a view or HTML, it will attempt to strip the HTML out.
352
+
353
+
Instead, you have available to you the `exportFormat()` method on your column, to define how you want this column to be formatted when outputted to the file.
354
+
355
+
So you can have a column that you want both available to the UI and the export, and format them differently based on where it is being outputted.
356
+
357
+
#### Exporting example
358
+
359
+
```php
360
+
<?php
361
+
362
+
namespace App\Http\Livewire;
363
+
364
+
use App\User;
365
+
use Illuminate\Database\Eloquent\Builder;
366
+
use Rappasoft\LaravelLivewireTables\TableComponent;
367
+
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
->exportFormat(function(User $model) { // This column is visible to both the UI and the export, but is formatted differently to the export via this method.
403
+
return $model->email;
404
+
}),
405
+
Column::make('Role', 'role.name') // This columns is visible to both the UI and export, and is rendered the same
406
+
->searchable()
407
+
->sortable(),
408
+
Column::make('Permissions') // This columns is visible to both the UI and export, and is rendered the same, except the HTML tags will be removed because it is not specifically calling a exportFormat() function.
->excludeFromExport(), // This column is visible to the UI, but not export.
419
+
];
420
+
}
421
+
}
422
+
```
423
+
424
+
#### Customizing Exports
425
+
426
+
Currently, there are no customization options available. But there is a config item called `exports` where you can define the class to do the rendering. You can use the `\Rappasoft\LaravelLivewireTables\Exports\Export` class as a base.
427
+
428
+
More options will be added in the future, but the built in options should be good for most applications.
429
+
430
+
### Setting Component Options
296
431
297
432
There are some frontend framework specific options that can be set.
298
433
@@ -304,6 +439,12 @@ They are done this way instead of the config file that way you can have per-comp
304
439
protected $options = [
305
440
// The class set on the table when using bootstrap
0 commit comments