F
Filament7mo ago
arsadi

Show Indicator on Custom Filter doesn't work

What I am trying to do: I am trying to display my custom date filter indicator. My filter contain 2 field, created_from and created_until What I did: I've add a method called indicateUsing() on my Custom Filter, I've follow the documentation here : https://filamentphp.com/docs/3.x/tables/filters/custom#multiple-active-indicators My issue/the error: I still don't get my indicators. even the filter counter dosn't work (still 0).
Solution:
It's work if I am not using deferFilters()
Jump to solution
3 Replies
arsadi
arsadiOP7mo ago
Code:
Filter::make('created_at')
->form([
DatePicker::make('created_from')
->label('Created from'),
DatePicker::make('created_until')
->label('Created until'),
])
->columns(2)
->columnSpan(2)
->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),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];

if ($data['created_from'] ?? null) {
$indicators[] = Indicator::make('Created from ' . Carbon::parse($data['created_from'])->toFormattedDateString())
->removeField('created_from');
}

if ($data['created_until'] ?? null) {
$indicators[] = Indicator::make('Created until ' . Carbon::parse($data['created_until'])->toFormattedDateString())
->removeField('created_until');
}

return $indicators;
})
Filter::make('created_at')
->form([
DatePicker::make('created_from')
->label('Created from'),
DatePicker::make('created_until')
->label('Created until'),
])
->columns(2)
->columnSpan(2)
->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),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];

if ($data['created_from'] ?? null) {
$indicators[] = Indicator::make('Created from ' . Carbon::parse($data['created_from'])->toFormattedDateString())
->removeField('created_from');
}

if ($data['created_until'] ?? null) {
$indicators[] = Indicator::make('Created until ' . Carbon::parse($data['created_until'])->toFormattedDateString())
->removeField('created_until');
}

return $indicators;
})
Solution
arsadi
arsadi7mo ago
It's work if I am not using deferFilters()
arsadi
arsadiOP7mo ago
I think this is a bug
Want results from more Discord servers?
Add your server