Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation examples for formatStates method and strip_tags for CSV headers #116

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,34 @@ Then use them in the templates as regular blade variables:
{{ $myVariable }}
```

## Customising Column States
By default the output for the export is a copy of the output from the table view. In some instances, you might wish to change this (e.g. remove HTML formatting or change date formatting to be more compatible with your spreadsheet application).

```php
public function table(Table $table): Table
{
return $table
...
->headerActions([
FilamentExportHeaderAction::make('export')->label(__('Export'))
->formatStates([
'first_name' => fn(Column $column):string => $column->getState(), // returns raw value
'last_name' => fn(string $state) :string => $state, // returns raw value
'fullname' => fn(Model $record) :string => $record->fullname . "\t", // returns value with appended character(s)
'middle_name' => function(Model $record) { // more complex example
$state = $record->middle_name;
if($middle_name == 'bob') {
// do some extra code/calculations
$state = 'not bob';
}
return $state;
}
])
,
]);
}
```

## Using Snappy

By default, this package uses [dompdf](https://github.com/barryvdh/laravel-dompdf) as pdf generator.
Expand Down
4 changes: 3 additions & 1 deletion src/FilamentExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function download(): StreamedResponse
}

return response()->streamDownload(function () {
$headers = $this->getAllColumns()->map(fn ($column) => $column->getLabel())->toArray();
$headers = $this->getAllColumns()->map(fn ($column) => strip_tags($column->getLabel()))->toArray();

$stream = SimpleExcelWriter::streamDownload("{$this->getFileName()}.{$this->getFormat()}", $this->getFormat(), delimiter: $this->getCsvDelimiter())
->noHeaderRow()
Expand Down Expand Up @@ -380,6 +380,8 @@ public static function getColumnState(Table $table, Column $column, Model $recor
break;
case 'index':
$dependencies[] = $index;
case 'state':
$dependencies[] = $column->getState();
break;
}
}
Expand Down