F
Filamentβ€’6mo ago
Robin

Export Action

When using ExportAction, is it possible to let the user select thier own custom date range, date A to date B instead of exporting all the rows? Also customize some values to only show once, like total, instead of showing the same value in all the exported rows?
Solution:
for the time I added a custom filter (from filament docs), that lets the user select from date A to date B, this is the code ``` ->filters([ Filter::make('created_at')...
Jump to solution
3 Replies
Robin
Robinβ€’6mo ago
nvm got a soultion for that, when using exportaction in a table it takes all the applied filters πŸ˜€
dhanar98
dhanar98β€’6mo ago
@Archie could you share the solution code here it is useful for other who are searching the answer mark this question as solved
Solution
Robin
Robinβ€’6mo ago
for the time I added a custom filter (from filament docs), that lets the user select from date A to date B, this is the code
->filters([

Filter::make('created_at')
->form([
DatePicker::make('created_from'),
DatePicker::make('created_until'),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['created_from'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
)
->when(
$data['created_until'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
}),
])
->filters([

Filter::make('created_at')
->form([
DatePicker::make('created_from'),
DatePicker::make('created_until'),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['created_from'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
)
->when(
$data['created_until'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
}),
])
the export action automatically gets the filters selected
Want results from more Discord servers?
Add your server
More Posts