Filament Excel exporting table data

Hey everyone, i have a problem about the exporting data from table. Here is my code:
protected function getTableBulkActions(): array
{
return [
ExportBulkAction::make()->exports([
ExcelExport::make('Table Data')
->fromTable()
->askForFilename($this->getTablePluralModelLabel() . ' ' . now()->format('d-m-Y H:i:s'))
->withColumns([
Column::make('answers.entry.created_at')
->heading('Ekleme Tarihi')
->formatStateUsing(fn($record) =>
$record->answers->first()->entry->created_at->format('d-m-Y H:i:s')
)
])
])
];
}
protected function getTableBulkActions(): array
{
return [
ExportBulkAction::make()->exports([
ExcelExport::make('Table Data')
->fromTable()
->askForFilename($this->getTablePluralModelLabel() . ' ' . now()->format('d-m-Y H:i:s'))
->withColumns([
Column::make('answers.entry.created_at')
->heading('Ekleme Tarihi')
->formatStateUsing(fn($record) =>
$record->answers->first()->entry->created_at->format('d-m-Y H:i:s')
)
])
])
];
}
It exports all columns with data but expect 2 column, and idk why its empty. Here is that table columns coming empty:
Tables\Columns\TextColumn::make('answers.value')
->label('Yanıtlar')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('answers.value')
->label('Yanıtlar')
->searchable()
->sortable(),
This column not exported, i mean its coming empty in excel report.
2 Replies
WolfMoon
WolfMoonOP2y ago
It's filled in table, but in exported file empty: https://i.imgur.com/b8BbBIB.png
Imgur
Dennis Koch
Dennis Koch2y ago
Is this one exported correctly?
Column::make('answers.entry.created_at')
->heading('Ekleme Tarihi')
Column::make('answers.entry.created_at')
->heading('Ekleme Tarihi')
answers is a HasMany relation? I don't think those are handled properly right now. You can work around this and format it yourself. Something similar to this:
Column::make('answers.value')->getStateUsing(
fn ($record) => $record->answers->pluck('values')->join(',')
)
Column::make('answers.value')->getStateUsing(
fn ($record) => $record->answers->pluck('values')->join(',')
)
Want results from more Discord servers?
Add your server